<<

Finding large prime

The pattern according to which prime numbers are distributed has always intrigued mathematicians.

“Mathematicians have tried in vain to this day to discover some order in the sequence of prime numbers, and we have reason to be- lieve that it is a mystery into which the human mind will never penetrate.” Leonhard Euler

However, the task of finding large prime numbers has not always been regarded as worthwhile anybody’s time. Nowadays, large prime numbers are intimately tied to , the theory of encoding and decoding. Algorithms that can efficiently factor large numbers, or at least determine whether or not they are prime, have become a central issue in all modern security considerations. This note discusses two types of very fast primality tests. The first, called the Miller-Rabin test, derives its speed from the fact that its answer is correct only with a certain probablity, which can be set arbitrarily high. The second test, called the Lucas-Lehmer test, never gives an incorrect answer but only works on numbers of a certain type, namely on Mersenne numbers.

A. The Miller-Rabin test This test is supposed to detect whether a large odd n is prime or not. Given n, s write n − 1 = 2 t, with t odd, and pick a random integer b with 1 6 b 6 n − 1. Then n is said to pass the Miller-Rabin primality test with respect to b if either

(i) n divides bt − 1, or

2rt (ii) n divides b + 1 for some integer r with 0 6 r < s.

Theorem.1 If n is a positive odd composite integer, then n will (incorrectly) pass the Miller-Rabin test with at most 25% of all possible b with 1 6 b 6 n−1. On the other hand, if an odd integer n > 1 fails the test for any integer b with 1 6 b 6 n − 1, then n is composite. This test can be carried out very efficiently on a computer. Its strength lies in a repeated application. If the n ever fails a test, it must be composite. However, if it has already passed k random tests, then it is a prime number with a probability of at least 1 − (1/4)k. For example, five passes will guarantee a prime with 99.9% certainty.

1A proof of this theorem can be found in many number theory books, such as “A course in number theory and cryptography” by Neal Koblitz (Springer-Verlag 1994).

1 Examples. Using the Mathematica command MillerRabin[n,b] provided on our course webpage, you can do some testing on your own. If, for example you would like to check whether

n = 2854495385411919762116571938898990272765493293 is a prime number, simply perform the following five random tests: n=2854495385411919762116571938898990272765493293 b=Random[Integer,{1,n-1}] 710603819363809209623567087656734062778519812 MillerRabin[n,b] Pass b=Random[Integer,{1,n-1}] 389810604822505720451872337770611887491739776 MillerRabin[n,b] Pass b=Random[Integer,{1,n-1}] 408734727200564577130546097811726427427501146 MillerRabin[n,b] Pass b=Random[Integer,{1,n-1}] 617460911337797972757482829051766764064799845 MillerRabin[n,b] Pass b=Random[Integer,{1,n-1}] 439910720341904275164112700972127116843802798 MillerRabin[n,b] Pass You now can be 1 − (1/4)5 = 99.9% sure that you have found a prime number. On the other hand the number

n = 29039440315048804366843381281296847489502771 fails the first test and is therefore definitely composite: n=29039440315048804366843381281296847489502771 b=Random[Integer,{1,n-1}] 8312336695354150715085976281650761254632513 MillerRabin[n,b] Fail You can verify for yourself that n = 9 will pass the test (incorrectly) with b = 1 and b = 8, that is for exactly 25% of all possible b’s. The integer n = 403, which is also composite, passes the test (incorrectly) for 18 of the 402 possible b’s; that is only 4.4%. As you experiment with this function you will learn that Mathematica has no difficulty applying this test to integers several hundred digits long.

2 B. Mersenne primes Numbers of the form 2n − 1, with n an integer greater than 1, are called Mersenne numbers. It is an exercise to verify that if a Mersenne number 2n − 1 is prime, then the exponent n must necessarily be prime also. For example, 25 − 1 = 31 is a prime. However, 211 − 1 = 89 · 23 is not a prime despite the fact that the exponent is a prime number. There is a remarkably simple primality test for Mersenne numbers, which is based on a sequence of numbers (Ln) known as Lucas numbers. They are defined recursively 2 as L1 = 4 and Ln+1 = (Ln) − 2. The test is known as the Lucas-Lehmer test: Theorem.2 Let p be a prime number. Then 2p − 1 is prime if and only if 2p − 1 divides Lp−1.

Note. The sequence (Ln) gets very large very quickly. So, if you would like to test p whether or not 2 − 1 divides Lp−1, you should compute the sequence (Ln) modulo m = 2p − 1. As of this writing, only 49 numbers have been found. The largest known prime number is the Mersenne prime 274,207,281 − 1. In 12-point Courier New font, this number would fill 8,055 letter-size pages with 1-inch margins. It was found by Curtis Cooper on January 7, 2016. To learn more about Mersenne primes or how to join the Great Mersenne Prime Search on the Internet, check out the links on our course webpage.

2For a proof, see M. Rosen “A proof of the Lucas-Lehmer test”, The American Mathematical Monthly 95 (1988), no. 9, 855–856.

3