Module 8 : Primality Testing

Lecture 2 : Fermat Primality Test

 

If we reach bk-1 , we computed bk-1a (n-1)/2 (mod n). The square of this is an-1, which must be 1 (mod n) if n is prime, by Fermat’s Theorem. Therefore, if n is prime, bk-1 ± 1 (mod n). All other choices mean that n is composite. Moreover, if bk-1 1 then, if we didn’t stop at an earlier step, bk-2212 (mod n) with bk-2  ±1 (mod n). This means that n is composite (and we can factor n).

Although all prime numbers will be detected through this test, however the converse is not true. There are numbers which pass this test but are composite, i.e n is composite and an-1 ≡ 1 (mod n)for all possible  bases a. Such numbers are called Carmichael numbers. For example 561 is a Carmichael number. Carmichael numbers are usually of the form (p1.p2.p3) where the number is product of primes.
An alternative and equivalent definition of Carmichael numbers is given by Korselt's criterion.
Theorem : 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 | n − 1 .

For example: 

561= 3.11.17  is square-free and 2 |560, 10|560, 16 |560.
1105= 5.13.17  is square-free and 4 |1104, 12|1104, 16 |1104.

Solovay-Strassen Primality test: let n be an odd integer. Choose several random integers a with 1<a<n-1.if


For some a, then n is composite. If


For all a, then n is probably prime.

Running time: O((log n)3). This follows from running times of separate parts of the algorithm: finding gcd, computing of Jacobi symbol, and finally computing powers of a.
Respectively, O((log n)2) + O((log n)2) + O((log n)3).

Definition 1. For odd n > 3, we define
We will use the following lemma.

Lemma 2.1. For odd n > 3, n is prime if and only if E(n) = Zn*

For the proof of the lemma, refer to the book Randomized Algorithms [1], Lemma 14.30.