06 Number Theory and RSA
06 Number Theory and RSA
What are the factors of 326,818,261,539,809,441,763,169? There is no known efficient algorithm. What is the greatest common divisor of 835,751,544,820 and 391,047,152,188? Euclids algorithm solves this efficiently. These two facts are the basis for the RSA public-key cryptosystem.
2/24/05
Factors
Factors (non-trivial divisors) of 20 are 2,4,5,10
Primes
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 1 is not prime There are infinitely many primes.
2/24/05
Unique Factorization
Divisibility by a prime
If p is prime and p | ab, then p | a or p | b.
Unique factorization
Every integer has a unique factorization as a product of primes. 5280 = 25 31 51 111
2/24/05
Division Theorem
For any integer a and any positive integer n, there are unique integers q and r, such that 0 r < n and a = qn+r. Quotient q and remainder r Notation: r = a mod n
2/24/05
2/24/05
Euclids Algorithm
For any nonnegative integer a and any positive integer b,
gcd(a,b) = gcd (b, a mod b)
Example
EUCLID(120, 23) = EUCLID(23, 5) = EUCLID(5, 3) = EUCLID(3, 2) = EUCLID(2, 1) = EUCLID(1, 0) =1 So 120 and 23 are relatively prime.
COT 5993 (Lec 14) 2/24/05 7
2/24/05
Example
120 / 23 = 5 r 5
So 5 = 120-523
23 / 5 = 4 r 3
So 3 = 23-45 = 234(120-523) = -4120+2123
5/3=1r2
So 2 = 5-13 = (120-523)-1(-4120+2123) = 5120-2623
3/2=1r1
So 1 = 3-12 = (-4120+2123)-1(5120-2623) = -9120+4723
COT 5993 (Lec 14) 2/24/05 9
Modular Arithmetic
We do all arithmetic modulo n. Powers of 3
1,3,9,27,81,243,
Powers of 3 modulo 7
1,3,2,6,4,5,1,3,2,6,4,5,
Fermats Theorem:
If p is prime and 1 a < p, then ap-1 = 1 (mod p) .
2/24/05
10
Multiplicative Inverses
If a is relatively prime to n, then there exists x such that ax = 1 (mod n). x is the multiplicative inverse of a (mod n). We can find x using the Extended Euclids Algorithm.
ax+ny=1 implies that ax = 1 (mod n)
Example
The multiplicative inverse of 23 (mod 120) is 47, since 1 = -9120 + 4723.
COT 5993 (Lec 14) 2/24/05 11
Let n = pq.
n = 326,818,261,539,809,441,763,169
Use Extended Euclids Algorithm to compute d, the multiplicative inverse of e (mod (n)).
d = 217,878,841,025,721,762,044,107
(e,n) is the RSA public key. (d,n) is the RSA private key. Encryption: E(M) = Me mod n. Decryption: D(C) = Cd mod n.
COT 5993 (Lec 14) 2/24/05 14
Fast Exponentiation
Since d is huge, Cd mod n cannot be computed navely. We can do it in 2log d multiplications: fun exp(C, d, n) = if d = 0 then 1 else if even(d) then exp(C*C mod n, d/2, n) else C*exp(C, d-1, n) mod n
2/24/05
15
Correctness of RSA
Encrypting and decrypting M gives D(E(M)) = E(D(M)) = Med (mod n). By the choice of e and d, we have ed = 1 + k(p-1)(q-1), for some k. Calculating mod p, if M 0 (mod p), then Med = M(Mp-1)k(q-1) = M(1)k(q-1) = M (mod p) using Fermats Theorem. And, of course, if M = 0 (mod p), then again Med = M (mod p).
COT 5993 (Lec 14) 2/24/05 16
2/24/05
17
Example
n = 326,818,261,539,809,441,763,169 e=3 d = 217,878,841,025,721,762,044,107 M = 12,345,678,901,234,567,890 Encryption: E(M) = Me mod n E(M) = 268,102,434,874,902,796,719,062 Decryption: D(C) = Cd mod n D(E(M)) = 12,345,678,901,234,567,890
COT 5993 (Lec 14) 2/24/05 18
2/24/05
20