90 likes | 206 Views
Cryptography. Inverses and GCD Piotr Faliszewski. gcd(a, 0) = a gcd(a, b) = gcd(b, a mod b) a = b*q + r Here: q = a / b r = a mod b (a – b*q). Key idea express the first argument in terms of the second. GCD(a,b). Let a, n – two integers A number a -1 s.t.
E N D
Cryptography Inverses and GCD Piotr Faliszewski
gcd(a, 0) = a gcd(a, b) = gcd(b, a mod b) a = b*q + r Here: q = a / b r = a mod b (a – b*q) Key idea express the first argument in terms of the second GCD(a,b)
Let a, n – two integers A number a-1 s.t. a*a-1= 1 (mod n) is called a multiplicative inverse of a Theorem if gcd(a,b) = d then there are integers x and y s.t.,ax + by = d Multiplicative Inverse
Let a, n – two integers If gcd( a, n ) = 1 then there are integers x,y: ax + ny = 1 then, x is a-1 Note ax + ny = 1 (mod n) ax = 1 (mod n) Theorem if gcd(a,b) = d then there are integers x and y s.t.,ax + by = d Multiplicative Inverse
gcd(a ,b), r0=a, r1 = b gcd( r0, r1 ) r0 = q1r1 + r2 r1 = q2r2 + r3 r2 = q3r3 + r4 ... rk-1 = qkrk + rk+1 rk = qk+1rk+1 +0 Idea: sequences (xi) and (yi) ri = axi + byi build as you go Computing x,y via GCD
gcd(a ,b), r0=a, r1 = b gcd( r0, r1 ) r0 = q1r1 + r2 r1 = q2r2 + r3 r2 = q3r3 + r4 ... rk-1 = qkrk + rk+1 rk = qk+1rk+1 +0 x0 = 1, y0 = 0 x1 = 0, y1 = 1 x2 = x0 - q1x1, y2 = y0 - q1y1 x3 = x1 - q2x2, y3 = y1 - q2y2 x4 = x2 - q3x3, y4 = y2 - q3y3 ... rk+1 = axk+1 + byk+1 xj+1 = xj-1 – qjxj yj+1 = yj-1 – qjyj Computing x,y via GCD
gcd(a ,b), r0=45, r1 = 20 gcd( 45, 20 ) r0 = q1 r1 + r2 45 = 2 20 + 5 r1 = q2 r2 + r3 20 = 4 5 + 0 x0 = 1, y0 = 0 x1 = 0, y1 = 1 x2 = x0 - q1x1, y2 = y0 - q1y1 x2 = 1 – 2 0, y2 = 0 – 2 1 x2 = 1, y2 = -2 r3 = 0 computation ended gcd(45, 20) = 5 = 451 – 220 Example: GCD(45, 20)
gcd(a ,b), r0=19, r1 = 7 gcd( 19, 7 ) 19 = 2 7 + 5 7 = 1 5 + 2 5 = 2 2 + 1 2 = 2 1 + 0 x0 = 1, y0 = 0 x1 = 0, y1 = 1 x2 = 1 – 2 0 = 1 y2 = 0 – 2 1 = -2 x3 = 0 – 1 1 = -1 y3 = 1 – 1 (-2) = 3 x4 = 1 – 2 (-1) = 3 y4 = -2 – 2 (3) = -8 19 3 + 7 (-8) = 57 - 56 = 1 Example: GCD(19, 7)
Problem: Solve 7x = 10 (mod 19) 11 7 = 1 (mod 19) Thus (11 7)x = 11 10 (mod 19) x = 110 (mod 19) x = 15 (mod 19) Getting the inverse via GCD we know that gcd(19, 7) = 1 7*(-8) + 19*3 = 1 -8 is the multiplicative inverse of 7 (mod 19) -8 = 19 - 8 = 11 (mod 19) Solving Linear Congruences