Carmichael Numbers
Recall Carmichael numbers are composite numbers that almost always fool the Fermat primality test. We can show that Carmichael numbers must have certain properties.
First we show they cannot be of the form where are distinct primes with . By the Chinese Remainder Theorem we have . Then Suppose is not a multiple of . Then (by Fermat we have ). Then if passes the Fermat test, we must have and hence , where . Since is cyclic, there are exactly choices for that satisfy .
Since is strictly smaller than , the greatest common divisor of and is at most . Thus at most half the choices for can fool the Fermat test. For primes used in RSA, is small with high probability, so the product will almost never fool the Fermat test, as mentioned earlier.
Next suppose is not squarefree, that is for some prime and . Then by the Chinese Remainder Theorem, . Any satisfies by Euler's Theorem, so if as well, then we must have where Since , is cyclic, exactly elements satisfy . As cannot divide , the largest possible value for is , giving an upper bound of probability that will pass the Fermat test.
Hence if is a Carmichael number, then is squarefree and is the product of at least three distinct primes.
Solovay-Strassen Test
Recall our first suggestion for improving the Fermat test was to check check that after checking (since there are no nontrivial square roots of unity modulo a prime).
We can improve this by checking instead that This is known as the Solovay-Strassen test, which we examine here for historical interest. Recall that the Jacobi symbol can be evaluated quickly using quadratic reciprocity.
Why does this help? From above we know that if is not squarefree then fails the Fermat test with probability at least . So we need only consider the case when is squarefree but composite, say where is prime.
By the Chinese Remainder Theorem any can be written as . For any nonzero we have by Fermat, so if then we have where .
If then is at most . Since is cyclic, this means at most elements of satisfy . That is, the probability will pass the Fermat test is at most .
On the other hand, if , then this implies . Since we have , so write . Then But we have and since there is a chance that is a quadratic residue, there is a chance that and fail the test.
In other words, for any composite (even a Carmichael number) the probability passes the Solovay-Strassen test is at most . This was the first algorithm discovered for finding large primes.
Miller-Rabin Test
The Miller-Rabin test surpasses the Solovay-Strassen test in every way: the probability a composite number passes is only , and no Jacobi symbol computations are required. Moreover, any that exposes the compositeness of in the Solovay-Strassen test also causes the Miller-Rabin test to fail.