cse 311: foundations of computing Spring 2015 Lecture 13: Primes, GCDs, modular inverses
review: repeated squaring Since a mod m β‘ a (mod m) for any a we have a 2 mod m = (a mod m) 2 mod m and a 4 mod m = (a 2 mod m) 2 mod m and a 8 mod m = (a 4 mod m) 2 mod m and a 16 mod m = (a 8 mod m) 2 mod m and a 32 mod m = (a 16 mod m) 2 mod m Can compute π π mod π for π = 2 π in only π steps
review: general algorithm ModPow(a, k, m) should compute π π mod π . If π == 0 then return 1 If (π mod 2 == 0) then return ModPow( π 2 mod π , π/2, π ) else return (π Γ ModPow( π, π β 1, π)) mod π π = 81453 = 10011111000101101 2 = 2 16 + 2 13 + 2 12 + 2 11 + 2 10 + 2 9 + 2 5 + 2 3 + 2 2 + 2 0 Total # of arithmetic operations ~ 4 Γ 16 = 64
primality An integer p greater than 1 is called prime if the only positive factors of p are 1 and p . A positive integer that is greater than 1 and is not prime is called composite .
pr prima imali lity An integer p greater than 1 is called prime if the only positive factors of p are 1 and p . A positive integer that is greater than 1 and is not prime is called composite .
fundame ament nt al al theore rem m of of ari rith thmetic ic Every positive integer greater than 1 has a unique prime factorization = 2 β’ 2 β’ 2 β’ 2 β’ 3 48 = 3 β’ 197 591 45,523 = 45,523 = 2 β’ 5 β’ 5 β’ 47 β’ 137 321,950 = 2 β’ 3 β’ 3 β’ 5 β’ 3,607 β’ 3,803 1,234,567,890
f ac actoriza orization ion If π is composite, it has a factor of size at most π .
eucl clid id β s s theor orem There are an infinite number of primes. Proof by contradiction: Suppose that there are only a finite number of primes: π 1 , π 2 , β¦ , π π
f amous ous algori gorithmic thmic problems oblems β’ Primality Testing β Given an integer π , determine if π is prime β Fermatβs little theorem test: If π is prime and π β 0 , then π πβ1 β‘ 1 (mod π) β’ Factoring β Given an integer π , determine the prime factorization of π
f ac actoring oring Factor the following 232 digit number [RSA768]: 123018668453011775513049495838496272077285 356959533479219732245215172640050726365751 874520219978646938995647494277406384592519 255732630345373154826850791702612214291346 167042921431160222124047927473779408066535 1419597459856902143413
123018668453011775513049495838496272077285356959533479219 732245215172640050726365751874520219978646938995647494277 406384592519255732630345373154826850791702612214291346167 042921431160222124047927473779408066535141959745985690214 3413 334780716989568987860441698482126908177047949837 137685689124313889828837938780022876147116525317 43087737814467999489 367460436667995904282446337996279526322791581643 430876426760322838157396665112792333734171433968 10270092798736308917
grea eate test st com ommo mon n di divisor isor GCD(a, b): Largest integer π such that π β£ π and π β£ π β GCD(100, 125) = β GCD(17, 49) = β GCD(11, 66) = β GCD(13, 0) = β GCD(180, 252) =
gcd d and and f ac actoring oring a = 2 3 β’ 3 β’ 5 2 β’ 7 β’ 11 = 46,200 b = 2 β’ 3 2 β’ 5 3 β’ 7 β’ 13 = 204,750 GCD(a, b) = 2 min(3,1) β’ 3 min(1,2) β’ 5 min(2,3) β’ 7 min(1,1) β’ 11 min(1,0) β’ 13 min(0,1) Factoring is expensive! Can we compute GCD(a,b) without factoring?
usef eful ul GCD D f ac act If π and π are positive integers, then gcd π, π = gcd(π, π mod π) Proof: By definition π = π div π β’ π + (π mod π) If π β£ π and π β£ π then π β£ π mod π . If π β£ π and π β£ π mod π then π β£ π .
eucl clid id β s s al algor orithm thm Repeatedly use the GCD fact to reduce numbers until you get GCD π¦, 0 = π¦. GCD(660,126)
eucl clid id β s s al algor orithm thm GCD(x, y) = GCD(y, x mod y) int GCD(int a, int b){ /* a >= b, b > 0 */ int tmp; while (b > 0) { tmp = a % b; a = b; b = tmp; } return a; } Example: GCD(660, 126)
Bezout out β s s theorem orem If a and b are positive integers, then there exist integers s and t such that gcd (a,b) = s a + t b
ex exten tended ded eu eucli clidea dean n algori orithm thm β’ Can use Euclidβs Algorithm to find π‘, π’ such that gcd π, π = π‘π + π’π β’ e.g. gcd(35,27): 35 = 1 β’ 27 + 8 35 - 1 β’ 27 = 8 27= 3 β’ 8 + 3 27- 3 β’ 8 = 3 8 = 2 β’ 3 + 2 8 - 2 β’ 3 = 2 3 = 1 β’ 2 + 1 3 - 1 β’ 2 = 1 2 = 2 β’ 1 + 0 β’ Substitute back from the bottom 1 = 3 - 1 β’ 2 = 3 β 1 (8 - 2 β’ 3) = ( -1 ) β’ 8 + 3 β’ 3 = (- 1 ) β’ 8 + 3 (27- 3 β’ 8 ) = 3 β’ 27 + ( -10 ) β’ 8 =
mu mul tiplic iplicative e inv nver erse e mod π Suppose GCD π, π = 1 By BΓ©zoutβs Theorem, there exist integers π‘ and π’ such that π‘π + π’π = 1. π‘ mod π is the multiplicative inverse of π : 1 = π‘π + π’π mod π = π‘π mod π
sol olving ing mo modu dula lar r equa uatio ions ns Solving ππ¦ β‘ π (mod π) for unknown π¦ when gcd π, π = 1 . 1. Find π‘ such that π‘π + π’π = 1 Compute π β1 = π‘ mod π , the multiplicative inverse of 2. π modulo π Set π¦ = π β1 β π mod π 3.
example ample Solve: 7π¦ β‘ 1 (mod 26)
Recommend
More recommend