cse 311 foundations of computing spring 2015 lecture 13
play

cse 311: foundations of computing Spring 2015 Lecture 13: Primes, - PowerPoint PPT Presentation

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


  1. cse 311: foundations of computing Spring 2015 Lecture 13: Primes, GCDs, modular inverses

  2. 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

  3. 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

  4. 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 .

  5. 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 .

  6. 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

  7. f ac actoriza orization ion If π‘œ is composite, it has a factor of size at most π‘œ .

  8. 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 , … , π‘ž π‘œ

  9. 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 π‘œ

  10. f ac actoring oring Factor the following 232 digit number [RSA768]: 123018668453011775513049495838496272077285 356959533479219732245215172640050726365751 874520219978646938995647494277406384592519 255732630345373154826850791702612214291346 167042921431160222124047927473779408066535 1419597459856902143413

  11. 123018668453011775513049495838496272077285356959533479219 732245215172640050726365751874520219978646938995647494277 406384592519255732630345373154826850791702612214291346167 042921431160222124047927473779408066535141959745985690214 3413 334780716989568987860441698482126908177047949837 137685689124313889828837938780022876147116525317 43087737814467999489 367460436667995904282446337996279526322791581643 430876426760322838157396665112792333734171433968 10270092798736308917

  12. 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) =

  13. 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?

  14. 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 𝑒 ∣ 𝑏 .

  15. 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)

  16. 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)

  17. 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

  18. 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 =

  19. 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 𝑛

  20. 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.

  21. example ample Solve: 7𝑦 ≑ 1 (mod 26)

Recommend


More recommend