SPsPDem
Strong Pseudoprime Test Demonstration
How the Strong Pseudoprime Test Works
The strong pseudoprime test (also known as the Miller-Rabin test) is a probabilistic primality test that determines whether a number is likely prime or definitely composite:
- 1First, we write where is odd, factoring out all powers of 2
- 2We compute using fast modular exponentiation
- 3If , then passes the test (strong probable prime)
- 4Otherwise, we repeatedly square the result: up to
- 5If any of these intermediate values equals , then passes the test
- 6If we find a value that squares to but is not , then is definitely composite
- 7Key insight: If but , then is composite
- 8This happens because , so gives a non-trivial factor
- 9The test is based on Fermat's Little Theorem
- 10If fails the test for any base , then is definitely composite
- 11If passes for many random bases, it is a strong probable prime with respect to base
- 12This test is widely used in cryptography for generating large prime numbers