Pick any number and ask: is it prime? The obvious strategy is trial division — test every number up to . That works, but it is painfully slow for the 1024-bit numbers used in RSA encryption.
A faster naive test exploits Fermat's Little Theorem: if is prime, then for every not divisible by . If that congruence fails for even one , the number is provably composite.
The catch: there are composite numbers that fool Fermat for every . The smallest is 561 = 3 × 11 × 17. These are called Carmichael numbers, and there are infinitely many of them. A pure Fermat test will always call 561 prime — it is wrong every single time.
Miller-Rabin (Gary Miller 1976, Michael Rabin 1980) fixes this by strengthening the condition. Instead of just checking , it also inspects the square roots that appear along the way. This extra check catches Carmichael numbers and, with enough random witnesses, makes an error essentially impossible.
Comments
Loading comments...