s Number Theory Lecture 14 Handout: Pseudoprimes and Probablistic Primality Tests
By Doron Zeilberger Recall that Fermats Little Theorem tells you that if p is prime, and a is such that 1 a p1 then we must have that a p1 1 (mod p) . But the converse is not always true, it could happen, (very rarely!) that x is composite, and nevertheless a x1 1 (mod x) . If that happens x is called Fermat pseudoprime to base a, or base-a pseudoprime. Important Fact: The smallest base-2 pseudoprime is the composite number 341 = 11 31. A composite number x that is a Fermat pseudoprime for any base a between 1 and p 1 is called a Charmaichael Number. We have Theorem (A. Korselt 1899): A positive composite integer n is a Carmichael number if and only if n is square-free, and for all prime divisors p of n, it is true that p 1 is divisible by n 1 Problem 14.1: Use Korslets theorem to show that 561 is a Carmichael number. Solution to 14.1: 561 = 3 11 17. Now (5611)/(31), (5611)/(111), and (5611)/(171) are all integers. Fermats Primality Test This should more appropriately called compositeness test. If a n1 1 (mod n) for some a then we know for sure that n is not prime. a is called a Fermat witness for the compositeness of n. Problem 14.2: Use the Fermat primality test to investigate wheter 33 is prime or composite. Solution to 14.2: The easiest witness to use is 2, so we start with a = 2, and hope for the best. We need to nd 2 32 (mod 33). 2 2 (mod 33) = 4 2 4 (mod 33) = 16 2 8 (mod 33) = 16 2 (mod 33) = 256 (mod 33) = 33 7 + 25 (mod 33) = 25 (mod 33) 2 16 (mod 33) = 25 2 (mod 33) = (8) 2 (mod 33) = 64 (mod 33) = 31 1 2 32 (mod 33) = 31 2 (mod 33) = (2) 2 (mod 33) = 4 . Since 2 32 1 (mod 33) we know for sure that 33 is composite. If we compute a n1 (mod n) for quite a few as and we always get 1 then there is a very good chance that n is a prime. Problem 14.3: Use the Fermat primality test to investigate whether 7 is a prime or composite, by picking two random as (if necessary) in the set {2, 3, 4, 5, 6}. Solution to 14.3: Lets pick a = 2 and a = 4, and nd a 6 (mod 7). 2 6 (mod 7) = 64 (mod 7) = 7 9 + 1 (mod 7) = 1 4 6 (mod 7) = 4096 = 7 585 + 1 (mod 7) = 1 We deduce with high probability that 7 is a prime, in other words it is a probable prime. Remark: Of course, it is much easier to check that 7 is a prime directly. The test is only useful for larger integers. The Miller-Rabin Primality Test Inputs: A positive integer n, and an integer a between 2 and n 2 Output: The knowledge that n is composite for sure, or a is a witness for the probable primality of n Step 1: By repeated division-by-2 (easy), write n 1 = 2 s d, where d is an odd integer, and s is an integer 0. Step 2: For i = 0, 1, . . . , s 1: 2.1: Compute a 2 i d (mod n) If for all of them, they are neither 1 nor 1 (alias n 1) output composite. Otherwise, keep trying several (say, R) randomly chosen as, and if all these witnesses testify, output n is very probably prime, using R random witnesses. Problem 14.4: Use the Miller-Rabin primality test to investigage whether 7 is a prime or composite by picking two (if necessary) random as in the set {2, 3, 4, 5, 6} Solution to 14.4: 7 1 = 6 = 2 3 so d = 3 and s = 1 2 With a = 2 2 3 (mod 7) = 1, so a = 2 is a witness to the primality of 7 With a = 3 3 3 (mod 7) = 1, so a = 3 is a witness to the primality of 7. Hence 7 is a probable prime with two witnesses. Problem 14.5: Use the Miller-Rabin primality test to decide whether 21 is prime or composite by picking (if necessary!) two random as in the set {2, 3, 4, 5, 6, 7, 8, 9} Solution to 14.5: 21 1 = 20 = 5 2 2 so d = 5 and s = 2 With a = 2 2 5 (mod 21) = 32 (mod 21) = 11, that is neither 1 nor 20 2 10 (mod 21) = 11 2 (mod 21) = 121 (mod 21) = 16, that is neither 1 nor 20 So we know, for sure, that 20 is composite. Ans. to 14.5: 20 is a composite number, by the Miller-Rabin test. 3