Lec 2
Lec 2
GCD
❑ The greatest common divisor (GCD) of two positive integers is
the largest integer that can divide both integers.
❑ The divisors of 30 are 1, 2, 3, 5, 6, 10, 15, 30
❑ The common divisors of 12 and 30 are 1, 2, 3, 6.
❑ GCD(12,30) = 6.
❑ When gcd (a, b) = 1, we say that a and b are relatively prime.
Introduction to Cryptography
GCD & Relatively Prime Numbers
Euclidean Algorithm
Extended Euclidean Algorithm (EEA)
Congruence
Residue Class
Operations in Zn
Arithmetic Tables
Why Euclidean Algorithm??
gcd (748, 2024) = 44
An efficient way to find the gcd (a, b), uses facts that:
❑ Fact1: gcd (a, 0) = a
❑ Fact2: gcd (a, b) = gcd (b, r)
where r is the remainder of dividing a by b
❑ gcd(a, b) = gcd(b, a mod b) r is replaced by a mod b
Euclidean Algorithm (Algo)
❑ gcd(a, b)
❑ Euclidean Algorithm to compute gcd(a, b) is:
Euclid(a, b)
if (b = 0) then return a;
else return Euclid(b, a mod b);
Euclidean Algorithm
gcd (36, 10) = gcd (10, 6) = gcd (6, 4) = gcd (4, 2) = gcd (2, 0) = 2
q r1 r2 r
36/10= 10*3+6 1 2740 1760 980
R=6, hence b=10, 1 1760 980 780
r=6 1 980 780 200
3 780 200 180
1 200 180 20
9 180 20 0
Find the greatest common
x 20 0 x
divisor of 2740 and 1760.
Introduction to Cryptography
Find the greatest common divisor of 25 and 60?
gcd(a, b) = as + bt
where s and t are integer coefficients, this equation is often referred to as
Diophantine equation
The question now is: how do we compute the two coefficients s and t?
r = r1 − q × r2, s = s1 − q × s2, t = t1 − q × t2
The Extended Euclidean Algorithm (EEA)
Ex: Given a = 161 and b = 28, find gcd (a, b) and the values of s and t.
Ex: Given a = 161 and b = 28, find gcd (a, b) and the values of s and t.
Two integers are congruent if their mod(n) gives the same result
❑ Congruence operator ( ≡ )
2 ≡ 12 (mod 10) 13 ≡ 23 (mod 10)
34 ≡ 24 (mod 10) -8 ≡ 12 (mod 10)