L29&30 - RSA Cryptography CSci/Math 2112 20&22 July 2015 1 / 13
Notation We write a mod n for the integer b such that 0 b < n and a b (mod n). 2 / 13
Calculating Large Powers Modulo n Example 1 What is 8 7 mod 71? 3 / 13
Calculating Large Powers Modulo n Example 1 What is 8 7 mod 71? Example 2 What is 5 11 mod 600? 3 / 13
Integers Modulo n Let n and a be positive integers such that gcd(a, n) = 1. Theorem Let x Z n. If x[a] = [0] then x = [0]. 4 / 13
Integers Modulo n Let n and a be positive integers such that gcd(a, n) = 1. Theorem Let x Z n. If x[a] = [0] then x = [0]. Proof. Let x Z n and x[a] = [0]. Let x = [b] for some integer 0 b < n. Then n (ab). Since gcd(a, n) = 1, we have n b, thus x = [0]. 4 / 13
Integers Modulo n Let n and a be positive integers such that gcd(a, n) = 1. Theorem Let x Z n. If x[a] = [0] then x = [0]. Proof. Let x Z n and x[a] = [0]. Let x = [b] for some integer 0 b < n. Then n (ab). Since gcd(a, n) = 1, we have n b, thus x = [0]. Theorem Let x, y Z n. If x[a] = y[a], then x = y. 4 / 13
Integers Modulo n Let n and a be positive integers such that gcd(a, n) = 1. Theorem Let x Z n. If x[a] = [0] then x = [0]. Proof. Let x Z n and x[a] = [0]. Let x = [b] for some integer 0 b < n. Then n (ab). Since gcd(a, n) = 1, we have n b, thus x = [0]. Theorem Let x, y Z n. If x[a] = y[a], then x = y. Proof. Let x, y Z n and x[a] = y[a]. Then x[a] y[a] = (x y)[a] = [0]. Since [a] [0], we have x y = [0], showing x = y. 4 / 13
Inverse Modulo n If gcd(x, n) = 1 then we can find a [y] Z n such that [x][y] = [1], i.e. xy 1 (mod n). The integer y is called the inverse of x modulo n. Example 3 Find the inverse of 4 modulo 7. 5 / 13
Inverse Modulo n If gcd(x, n) = 1 then we can find a [y] Z n such that [x][y] = [1], i.e. xy 1 (mod n). The integer y is called the inverse of x modulo n. Example 3 Find the inverse of 4 modulo 7. Example 4 Find the inverse of 9 modulo 50. 5 / 13
Fermat s Little Theorem Lemma If p is a prime and k an integer such that 0 < k < p then p ( p k). 6 / 13
Fermat s Little Theorem Lemma If p is a prime and k an integer such that 0 < k < p then p ( p k). Theorem (Fermat s Little Theorem) If p is a prime and a is an integer, then a p a (mod p). 6 / 13
Fermat s Little Theorem Lemma If p is a prime and k an integer such that 0 < k < p then p ( p k). Theorem (Fermat s Little Theorem) If p is a prime and a is an integer, then a p a (mod p). Example 5 Find 8 6 mod 7. 6 / 13
Euler s Totient Function Euler s Totient Function of n, denoted by φ(n), is the number of positive integers a less than (or equal to) n such that gcd(a, n) = 1. Example 6 Find φ(1), φ(9), φ(12), φ(23) and φ(6). 7 / 13
Euler s Totient Function Euler s Totient Function of n, denoted by φ(n), is the number of positive integers a less than (or equal to) n such that gcd(a, n) = 1. Example 6 Find φ(1), φ(9), φ(12), φ(23) and φ(6). Proposition If gcd(m, n) = 1, then φ(mn) = φ(m)φ(n). 7 / 13
Euler s Totient Function Euler s Totient Function of n, denoted by φ(n), is the number of positive integers a less than (or equal to) n such that gcd(a, n) = 1. Example 6 Find φ(1), φ(9), φ(12), φ(23) and φ(6). Proposition If gcd(m, n) = 1, then φ(mn) = φ(m)φ(n). Example 7 Find φ(207). 7 / 13
Euler s Totient Function Proposition For a prime p we have φ(p) = p 1. 8 / 13
Euler s Totient Function Proposition For a prime p we have φ(p) = p 1. Proposition ) For a prime p we have φ(p k ) = p k p k 1 = p (1 k 1 p. 8 / 13
Euler s Totient Function Proposition For a prime p we have φ(p) = p 1. Proposition ) For a prime p we have φ(p k ) = p k p k 1 = p (1 k 1 p. Proposition For any positive integer n we have φ(n) = n ( 1 1 ). p p n 8 / 13
Euler s Totient Function Proposition For a prime p we have φ(p) = p 1. Proposition ) For a prime p we have φ(p k ) = p k p k 1 = p (1 k 1 p. Proposition For any positive integer n we have φ(n) = n ( 1 1 ). p p n Example 8 Find φ(345). 8 / 13
Euler s Theorem Theorem (Euler s Theorem) Let a, n N with gcd(a, n) = 1. Then a φ(n) 1 (mod n). 9 / 13
Euler s Theorem Theorem (Euler s Theorem) Let a, n N with gcd(a, n) = 1. Then a φ(n) 1 (mod n). Example 9 Find 7 176 mod 345. 9 / 13
RSA Cryptography Alice wants to send Bob a secure message. 10 / 13
RSA Cryptography Alice wants to send Bob a secure message. They decide to use an RSA code. 10 / 13
RSA Cryptography Alice wants to send Bob a secure message. They decide to use an RSA code. Bob will do the following: 10 / 13
RSA Cryptography Alice wants to send Bob a secure message. They decide to use an RSA code. Bob will do the following: Pick two primes p and q. 10 / 13
RSA Cryptography Alice wants to send Bob a secure message. They decide to use an RSA code. Bob will do the following: Pick two primes p and q. Calculate n = pq and φ(n) = (p 1)(q 1). 10 / 13
RSA Cryptography Alice wants to send Bob a secure message. They decide to use an RSA code. Bob will do the following: Pick two primes p and q. Calculate n = pq and φ(n) = (p 1)(q 1). Pick an integer e such that gcd(e, φ(n)) = 1. 10 / 13
RSA Cryptography Alice wants to send Bob a secure message. They decide to use an RSA code. Bob will do the following: Pick two primes p and q. Calculate n = pq and φ(n) = (p 1)(q 1). Pick an integer e such that gcd(e, φ(n)) = 1. Calculate the inverse d of e modulo φ(n). 10 / 13
RSA Cryptography Alice wants to send Bob a secure message. They decide to use an RSA code. Bob will do the following: Pick two primes p and q. Calculate n = pq and φ(n) = (p 1)(q 1). Pick an integer e such that gcd(e, φ(n)) = 1. Calculate the inverse d of e modulo φ(n). Make n and e public. 10 / 13
RSA Cryptography Alice wants to send Bob a secure message. They decide to use an RSA code. Bob will do the following: Pick two primes p and q. Calculate n = pq and φ(n) = (p 1)(q 1). Pick an integer e such that gcd(e, φ(n)) = 1. Calculate the inverse d of e modulo φ(n). Make n and e public. Alice calculates r x e (mod n) where x is her message, and sends r to Bob. 10 / 13
RSA Cryptography Alice wants to send Bob a secure message. They decide to use an RSA code. Bob will do the following: Pick two primes p and q. Calculate n = pq and φ(n) = (p 1)(q 1). Pick an integer e such that gcd(e, φ(n)) = 1. Calculate the inverse d of e modulo φ(n). Make n and e public. Alice calculates r x e (mod n) where x is her message, and sends r to Bob. Bob calculates r d mod n. 10 / 13
RSA Cryptography Example 10 Bob decides to use p = 5 and q = 7. Then n = 35 and φ(n) = 24. He picks e = 5, thus d = 5. He then makes n and e public. Alice wants to send HI to Bob, which becomes the two separate messages 8 and 9. Which numbers should she send to Bob? 11 / 13
RSA Cryptography Example 10 Bob decides to use p = 5 and q = 7. Then n = 35 and φ(n) = 24. He picks e = 5, thus d = 5. He then makes n and e public. Alice wants to send HI to Bob, which becomes the two separate messages 8 and 9. Which numbers should she send to Bob? Example 11 Bob receives the following message: 33, 15, 9, 10. What was Alice s original message? 11 / 13
RSA Cryptography Example 10 Bob decides to use p = 5 and q = 7. Then n = 35 and φ(n) = 24. He picks e = 5, thus d = 5. He then makes n and e public. Alice wants to send HI to Bob, which becomes the two separate messages 8 and 9. Which numbers should she send to Bob? Example 11 Bob receives the following message: 33, 15, 9, 10. What was Alice s original message? Example 12 Thief C intercepted a message from Alice to Bob. They know that Bob has n = 391 and e = 7. They also know that they need to find d to decypher the message. What should they do? 11 / 13
RSA Cryptography Example 13 12 / 13
RSA Cryptography Why is Bob able to decypher Alice s message? Since de 1 (mod φ(n)), we have de = kφ(n) + 1 for some integer k. 13 / 13
RSA Cryptography Why is Bob able to decypher Alice s message? Since de 1 (mod φ(n)), we have de = kφ(n) + 1 for some integer k. Using Euler s Theorem, we have x de = x (x φ(n)) k x (1) k (mod n) x (mod n). 13 / 13