Definition (Miller-Rabin Primality Testing)

Suppose is a positive odd integer and write for some positive integer and an odd number . Suppose is an integer between and . If is prime, then one of the following congruence relations most hold true:

If is not a strong probable prime to base , then is called a witness for the compositeness of , or a Miller-Rabin witness for .

If , it is a prime. Otherwise, if is even, output not a prime. Otherwise, we repeat for total random bases for . If we end without showing that is a witness, then is a prime.

If the number of times this is repeated is , the probability of being a prime is .

Example 1

Check that is a strong probable prime to the base .

  1. .
  2. So, .
  3. Now, we check for , so .
  4. Then, calculate
  1. This is not or . Both fail.
  2. Check

This is true. This is a strong probable prime.

Example 2

Check that is a witness for .

  1. .
  2. Then
  3. Check , and
  4. Then, calculate
    1. . Both conditions fail.
    2. .
  5. Since both fail, is a witness for ‘s composite.