Primality: Fermat Test and Carmichael Numbers

17 Dec 2021


§ Motivation

We can use number theoretic approaches to hopefully find methods of determining primality faster than the naïve method.

§ Distribution of Primes

Prime Distribution

Let π(x)\pi(x) be the number of primes less than or equal to xx, then

π(x)xlogx,\pi(x) \sim \frac{x}{\log x},

in other words

limxπ(x)xlogx=1.\lim_{x\to\infty} \frac{\pi(x)}{\frac{x}{\log x}} = 1.

In the case of RSA, we want very large primes, using Lemma 15.1 we can estimate the number of primes in a given interval. Say that we wanted to know how many primes exist in the range from 1010010^{100} and 2101002\cdot10^{100}. Then, the number of primes we can expect in this interval is given by

π(210100)π(10100)10100100log101098.\pi\left(2\cdot 10^{100}\right) -\pi\left(10^{100}\right) \sim \frac{10^{100}}{100\log{10}} \sim 10^{98}.

We see from the lemma that there exist many primes in this interval, so the odds of generating a random prime in this interval is not vanishingly small.

The following theorem is something that came up in class and I thought it was interesting.

Chebychev's Theorem (Bertrand's Postulate)

For any integer n>3n \gt 3, there exists at least one prime number pp in the interval

n<p<2n2.n \lt p \lt 2n - 2.

§ Fermat Primality Test

Fermat Primality Test

From the results of Fermat's Little Theorem, if pp prime then the following holds

ap11(modp).a^{p-1} \equiv 1 \pmod{p}.

However, not all numbers satisfying this congruence are prime.

Carmichael Numbers

Composite numbers nn that satisfy the following congruence are called Carmichael numbers,

ana(modn).a^n \equiv a \pmod{n}.

It should be noted that there exists infinitely many Carmichael numbers, so we cannot rely solely on the Fermat primality test.

Carmichael Number

The smallest Carmichael number is n=561n=561, which is divisible by 33.

Using Magma, we can compute a560(mod561)a^{560} \pmod{561} using the command:

Modexp(a, 560, 561);

Where a is to be replaced by any integer.

When testing we will see that for any choice of a it will yield 11.