Cryptography and computer security 2015/16 Tutorial 2: Euclidean Algorithm, Chinese remainder theorem Professor: Aleksandar Jurišić Assistant: Peter Nose Number theory Theory • The Euclidean Algorithm. Let a, b ∈ Z, a > b > 0. The greatest common divisor gcd(a, b) can be computed by an iterated division with remainder. Let r0 = a, r1 = b and r0 = q1 r1 + r2 (0 < r2 < r1 ), r1 = q2 r2 + r3 (0 < r3 < r2 ), .. . .. . rk−1 = qk rk + rk+1 (0 < rk+1 < rk ), .. . .. . rn−2 = qn−1 rn−1 + rn (0 < rn < rn−1 ), rn−1 = qn rn + rn+1 (0 = rn+1 ). The last non-zero remainder rn is the greatest common divisor gcd(a, b). • The Euclidean algorithm runs in time O(log(a) log(b)). Exercises 1. Calculate gcd(264, 210), gcd(975, 124) and gcd(89, 55). 2. In the Euclidean algorithm, prove that (a) the algorithm halts after finite number of steps, (b) gcd(a, b) = gcd(r0 , r1 ) = gcd(r1 , r2 ) = · · · = gcd(rn−1 , rn ) = rn , (c) rk > 2rk+2 for all k such that 0 ≤ k ≤ n − 2, (d) n is O(log a) and O(log b), (e) the running time is bounded by O((log(a))3 ), (f) the algorithm runs in time O(log(a) log(b)). 3. Find the worst-case inputs for the Euclidean algorithm. 4. Show how to compute lcm(a, b) in time O(log(a) log(b)). √ 5.* Denote α = (1 + 5)/2 ≈ 1,618. In the Euclidean algorithm, prove that (a) α2 = α + 1, (b) rn−i ≥ αi for all 0 ≤ i ≤ n − 1, (c) the number of divisions is less or equal then logα (a), (d) the previous bound is tight. 1 Theory • The Chinese Remainder Theorem. Let m1 , m2 , . . . , mr be pairwise relatively prime numbers, i.e., gcd(mi , mj ) = 1 for i 6= j. Let a1 , a2 , . . . , ar be arbitrary integers. Then the system of r congruences x ≡ ai (mod mi ) (1 ≤ i ≤ r) has a unique solution modulo M = m1 m2 · · · mr , which is given by ! r X x= ai Mi yi mod M, i=1 where Mi = M/mi and yi = Mi−1 mod mi , for i = 1, . . . , r. Exercises 1. Show that in the Chinese remainder theorem the system of congruences has a unique solution modulo M . 2. Great-grandmother refuses to say how old she is. She said that a year ago the number of her years was divisible by 3, in two years it will be divisible by 5, and in four years by 7. How old is she? 3. Solve the following system: x≡1 (mod 2) x≡1 (mod 5) x≡1 (mod 3) x≡1 (mod 6) x≡1 (mod 4) x≡0 (mod 7) 2
© Copyright 2026 Paperzz