Topics | Register • News • History • How to • Sequences statistics • Template prototypes |
Miller-Rabin pseudoprimality test
The Miller-Rabin pseudoprimality test is based in two facts for prime numbers:
- The Fermat Little Theorem that states:
. - If
then or .
Let
Then consider the sequence
If a member of the sequence is 1 but the previous is not 1 or -1, or the last member is not 1, the number is composite.
Otherwise the number is either a prime or a Miller-Rabin pseudoprime (sometimes called a strong pseudoprime) with respect to base
Usually, several tests are performed with different bases in order to increase the confidence that the number is not composite. If
Factoring Fermat pseudoprimes
Many pseudoprimes that pass the Fermat pseudoprimality test can be factored using the sequence defined above.
When
Another proper factor is:
Example
Let N = 561. Then N-1 = 24 × 35. Since the exponent is 4, the sequence will use exponents from zero to 4.
The Miller-Rabin sequence for base 5 is:
- r = 0:
- r = 1:
- r = 2:
- r = 3:
- r = 4:
Notice that in this case the number is a Fermat pseudoprime, because the sequence ends with the number 1, but according with the Miller-Rabin test the number is definitely composite, because before the number 1 we got a number which is not 1 or 560.
If we want to find factors of this number we can perform:
- gcd(67-1, 561) = 33
- gcd(67+1, 561) = 17