Navigation
Topics Register • News • History • How to • Sequences statistics • Template prototypes

Miller-Rabin pseudoprimality test

提供: Prime-Wiki
移動先: 案内検索

The Miller-Rabin pseudoprimality test is based in two facts for prime numbers:

  • The Fermat Little Theorem that states: ap11(modp).
  • If m21(modp) then m1(modp) or m1(modp).

Let N be an odd number being tested for primality, and N=2nk+1 where k is an odd number.

Then consider the sequence ak, a2k, a4k..., aN1 modulo N. This sequence should end with 1 because of the Fermat Little theorem.

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 a.

Usually, several tests are performed with different bases in order to increase the confidence that the number is not composite. If k different random pairwise-relatively-prime bases less than N are choosen for the Miller-Rabin test, and N passes all k tests, then the probability that N is composite is less than 1/4k. Conversely, it can be demonstrated that a composite N will only pass at most (N1)/4 such tests.

Factoring Fermat pseudoprimes

Many pseudoprimes that pass the Fermat pseudoprimality test can be factored using the sequence defined above.

When a(2rk)±1(modN) and a(2r+1k)1(modN), a proper factor of N is:

gcd(N,a(2rk)+1modN)

Another proper factor is:

gcd(N,a(2rk)1modN)

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: 53523(mod561)
  • r = 1: 232529(mod561)
  • r = 2: 5292463(mod561)
  • r = 3: 463267(mod561)
  • r = 4: 6721(mod561)

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

External links