A web application to test whether a number is prime using three classical algorithms: Miller–Rabin, Solovay–Strassen, and Baillie–PSW, with real-time benchmarking and comparison.
Determining whether a large number is prime is a fundamental problem in number theory with direct applications in cryptography (RSA, key generation, etc.). While trial division works for small numbers, it becomes computationally infeasible for large inputs. Probabilistic and hybrid tests offer a practical solution: they run in polynomial time and can decide primality with a controllable, extremely low error probability.
A probabilistic test based on Fermat's little theorem and the properties of strong pseudoprimes. It writes n - 1 = 2^k * m and checks, for several random bases a, whether a^m ≡ 1 (mod n) or a specific squaring condition holds. Each round has at most a 1/4 chance of a false positive, so running k = 10 rounds gives an error probability below 4^-10. Fast and widely used in practice.
One of the first probabilistic primality tests, introduced in 1977. It uses the Jacobi symbol to check whether a^((n-1)/2) ≡ (a/n) (mod n) holds for random bases a. Any composite number fails this test for at least half of all possible bases, giving an error probability of at most 2^-k after k rounds. Slightly less reliable than Miller–Rabin for the same number of rounds.
A hybrid test combining two independent checks: a Miller–Rabin strong probable prime test with base 2, followed by a strong Lucas probable prime test using Selfridge's parameters. The two tests are based on different mathematical foundations, making it extremely unlikely for a composite to pass both. No composite has ever been found that fools Baillie–PSW, making it near-deterministic for all practical inputs.
project/
├── static/
│ └── css/
│ └── style.css # Web interface styles
├── templates/
│ └── index.html # Main HTML template
├── app.py # Flask application
├── Primality_tests.py # Primality algorithm implementations
└── requirements.txt # Python dependencies
python -m venv venvWindows:
venv\Scripts\activateLinux / Mac:
source venv/bin/activatepip install -r requirements.txtpython app.pyhttp://127.0.0.1:5000/
To stop the server, press Ctrl + C in the terminal.
- Enter any integer in the input field
- Click the button to run the tests
- The page displays for each algorithm:
- Result: Prime or Composite
- Execution time in milliseconds
- Type: Probabilistic or Hybrid
- Reliability: Medium / High / Very High
- A message indicates whether all three algorithms agree on the result (disagreement may suggest a pseudoprime)