1 / 58

Addition

Addition. How fast can you add A+B. Addition. How fast can you add A+B. 1 0 1 0 1 1 1 0 0 1 1 0 0 1 0 0 1 1 1. Addition. How fast can you add A+B. 1 0 1 0 1 1 1 0 0 1 1 0 0 1 0 0 1 1 1 0. Addition. How fast can you add A+B. 1 0 1 0 1 1 1 0 0 1

walda
Download Presentation

Addition

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Addition How fast can you add A+B

  2. Addition How fast can you add A+B • 1 0 1 0 1 1 1 0 0 1 • 1 0 0 1 0 0 1 1 1

  3. Addition How fast can you add A+B • 1 0 1 0 1 1 1 0 0 1 • 1 0 0 1 0 0 1 1 1 • 0

  4. Addition How fast can you add A+B • 1 0 1 0 1 1 1 0 0 1 • 1 0 0 1 0 0 1 1 1 • 0 0

  5. Addition How fast can you add A+B • 1 0 1 0 1 1 1 0 0 1 • 1 0 0 1 0 0 1 1 1 • 1 0 0

  6. Addition How fast can you add A+B • 1 0 1 0 1 1 1 0 0 1 • 1 0 0 1 0 0 1 1 1 1 1 1 1 0 1 1 1 0 0 n-bit numbers  time = O(n)

  7. Multiplication How fast can you multiply A*B • 1 0 1 0 1 1 1 0 0 1 • *1 0 1 1

  8. Multiplication How fast can you multiply A*B • 1 0 1 0 1 1 1 0 0 1 • *1 0 1 1 • 1 0 1 0 1 1 1 0 0 1 • 1 0 1 0 1 1 1 0 0 11 0 1 0 1 1 1 0 0 1

  9. Multiplication How fast can you multiply A*B • 1 0 1 0 1 1 1 0 0 1 • *1 0 1 1 • 1 0 1 0 1 1 1 0 0 1 • 1 0 1 0 1 1 1 0 0 11 0 1 0 1 1 1 0 0 1 n-bit numbers  time = O(n2)

  10. Karatsuba-Offman a=2n/2 a1 + a0 b=2n/2 b1 + b0 ab=(2n/2a1+a0)(2n/2b1+b0) = 2n a1 b1 + 2n/2 (a1 b0 + a0 b1) + a0 b0

  11. Karatsuba-Offman a=2n/2 a1 + a0 b=2n/2 b1 + b0 Multiply(a,b,n) if n=1 return a*b else R1 Multiply(a1,b1,n/2) R2 Multiply(a0,b1,n/2) R3 Multiply(a1,b0,n/2) R4 Multiply(a0,b0,n/2) return 2n R1+ 2n/2 (R2+R3) + R4

  12. Karatsuba-Offman Multiply(a,b,n) if n=1 return a*b else R1 Multiply(a1,b1,n/2) R2 Multiply(a0,b1,n/2) R3 Multiply(a1,b0,n/2) R4 Multiply(a0,b0,n/2) return 2n R1+ 2n/2 (R2+R3) + R4 Recurrence?

  13. Karatsuba-Offman Multiply(a,b,n) if n=1 return a*b else R1 Multiply(a1,b1,n/2) R2 Multiply(a0,b1,n/2) R3 Multiply(a1,b0,n/2) R4 Multiply(a0,b0,n/2) return 2n R1+ 2n/2 (R2+R3) + R4 Recurrence? T(n) = 4T(n/2) + O(n)

  14. Karatsuba-Offman T(n) = 4T(n/2) + O(n) T(n)=O(n2)

  15. Karatsuba-Offman ab=(2n/2a1+a0)(2n/2b1+b0) = 2na1 b1 + 2n/2 (a1 b0 + a0 b1) + a0 b0 Can compute in less than 4 multiplications?

  16. Karatsuba-Offman ab=(2n/2a1+a0)(2n/2b1+b0) = 2na1 b1 + 2n/2 (a1 b0 + a0 b1) + a0 b0 Can compute using 3 multiplications: (a0+a1)(b0+b1) = a0b0 + (a1 b0 + a0 b1) + a1 b1

  17. Karatsuba-Offman Multiply(a,b,n) if n=1 return a*b else R1 Multiply(a1,b1,n/2) R2 Multiply(a0,b0,n/2) R3 Multiply(a1+a0,b1+b0,n/2+1) R4 R3 – R2 – R1 return 2n R1+ 2n/2 R3 + R2 Recurrence?

  18. Karatsuba-Offman Multiply(a,b,n) if n=1 return a*b else R1 Multiply(a1,b1,n/2) R2 Multiply(a0,b0,n/2) R3 Multiply(a1+a0,b1+b0,n/2+1) R4 R3 – R2 – R1 return 2n R1+ 2n/2 R3 + R2 Recurrence? T(n) = 3T(n/2) + O(n)

  19. Karatsuba-Offman T(n) = 3T(n/2) + O(n) T(n)=O(nC) C=log2 3  1.58

  20. Integer Division r=a mod b a,b  q,r a = q*b + r 0  r < b Can be done in O(n2) time.

  21. d divides a DEFINITION: d divides a (denoted d | a) if there exists b such that b*d = a 3|6 3|0 0|3 0|0

  22. d divides a DEFINITION: d divides a (denoted d | a) if there exists b such that b*d = a 3|6 yes, b=2 3|0 yes, b=0 0|3 no 0|0 yes, b=?

  23. d divides a 3|6 yes, b=2 3|0 yes, b=0 0|3 no 0|0 yes, b=? d | a  a | c  d | c Proof: a = b*d, c=b’*a  c=(b*b’)*d

  24. Divisibility poset 0 8 10 9 4 6 3 5 7 2 1

  25. GCD GCD (a,b) “largest” d such that d|a, d|b

  26. GCD GCD (a,b) “largest” d such that d|a, d|b d|a, d|b (c; c|a,c|b) : c|d GCD(3,6) GCD(0,8) GCD(0,0)

  27. GCD GCD (a,b) “largest” d such that d|a, d|b d|a, d|b (c; c|a,c|b) : c|d GCD(3,6) = 3 GCD(0,8) = 8 GCD(0,0) = 0

  28. GCD How quickly can we compute GCD (a,b) ?

  29. GCD How quickly can we compute GCD (a,b) ? Euclid GCD(a,b) = GCD(b,a mod b)

  30. GCD wlog a>b GCD(a,b) if b=0 then return a else return GCD(b,a mod b) Running time?

  31. GCD wlog a>b GCD(a,b) if b=0 then return a else return GCD(b,a mod b) Running time? (a,b)(b,a mod b)(a mod b, ?) (a mod b) < a/2

  32. GCD (a,b)(b,a mod b)(a mod b, ?) (a mod b) < a/2 2(log2 a)=O(n) iterations each mod O(n2) time  O(n3) time total

  33. Modular exponentiation (a,b,m)  ab mod m

  34. Modular exponentiation (a,b,m)  ab mod m b = 10101 a mod m a2 mod m a4 mod m a8 mod m a16 mod m ... ab mod m

  35. Modular exponentiation (a,b,m)  ab mod m mod-ex(a,b,m) if b=0 then RETURN 1 else if b mod 2 = 0 then RETURN mod-ex(a,b/2,m)2 mod m else RETURN a*mod-ex(a,(b-1)/2,m)2 mod m

  36. Algorithms so far a,b,m n-bit integers addition a+b O(n) time multiplication a*b O(n1.58) time division a/b,a mod b O(n2) time gcd(a,b) O(n3) time ab mod m O(n3) time

  37. GROUP (G,) is a group if  : GG  G (ab)c = a(bc) exists  G (aG) a = a a  a-1 aa-1=

  38. Modular arithmetic modulo m G = {0,...,m-1} = Zm ab = a+b mod m (G,) is a group if  : GG  G (ab)c = a(bc) exists  G (aG) a = a a  a-1 aa-1=

  39. Modular arithmetic modulo m G = {0,...,m-1} = Zm ab = a+b mod m (G,) is a group if  : GG  G (ab)c = a(bc) exists  G (aG) a = a a  a-1 aa-1= IS A GROUP

  40. Modular arithmetic modulo m G = {0,...,m-1} = Zm ab = a*b mod m (G,) is a group if  : GG  G (ab)c = a(bc) exists  G (aG) a = a a  a-1 aa-1=

  41. Modular arithmetic modulo m G = {0,...,m-1} = Zm ab = a*b mod m (G,) is a group if  : GG  G (ab)c = a(bc) exists  G (aG) a = a a  a-1 aa-1= b; ab=1 [mod m]  GCD(a,m)=1

  42. Modular arithmetic modulo m G = Z*m ={a | GCD(a,m)=1 } ab = a*b mod m (G,) is a group if  : GG  G (ab)c = a(bc) exists  G (aG) a = a a  a-1 aa-1= IS A GROUP

  43. Fermat’s little Theorem p a prime ap-1 = 1 [mod p] {ak | k Z} is a subgroup of Z*p

  44. Fermat’s little Theorem a(m)=1 [mod m] (m) = | Z*m | m=p1a1 p2a2 ... pkak (m) = (1-1/p1) ... (1-1/pk) m

  45. Fermat’s little Theorem m=p1a1 p2a2 ... pkak (m) = (1-1/p1) ... (1-1/pk) m E.g. if m=pq p,q primes (m)=

  46. Fermat’s little Theorem m=p1a1 p2a2 ... pkak (m) = (1-1/p1) ... (1-1/pk) m E.g. if m=pq p,q primes (m)=(p-1)(q-1)

  47. Fermat’s little Theorem a(p-1)(q-1) =1 [mod pq] E.g. if m=pq p,q primes (m)=(p-1)(q-1)

  48. RSA • choose primes p,q • let n  pq • choose e • compute • d=e-1 [mod (p-1)(q-1)] • 5) announce n,e

  49. RSA • choose primes p=13,q=17 • let n  pq • choose e • compute • d=e-1 [mod (p-1)(q-1)] • 5) announce n,e

  50. RSA • choose primes p=13,q=17 • let n  pq=221 • choose e • compute • d=e-1 [mod (p-1)(q-1)] • 5) announce n,e

More Related