b2KIT

Prime Number Tester & Generator

Test primality using Miller-Rabin algorithm. Generate large primes for cryptographic key generation.

Tested tool guide Tested browser tools Checked August 16, 2026

What Prime Number Tester & Generator does, with a checked example

Paste any integer and the tool answers yes or no: is it prime? It runs the Miller-Rabin test, the algorithm behind RSA and Diffie-Hellman key generation. Give it a bit length and it also produces a random prime of that size. Two things surprise users. For large numbers the verdict is probabilistic: each extra round shrinks the worst-case error by a factor of four, and only small numbers get a definitive answer. And testing primality is not factoring: a composite result comes back without its factors.

Worked example

A concrete input and expected output from the current implementation.

Input

1000000007

Expected output

Prime

1,000,000,007 is the well-known 10^9 + 7 prime used as a modulus in competitive programming. Because the number sits far below 3.47 trillion, the fixed-base version of Miller-Rabin is exact here: the answer is a proof, not a probability.

How the result is produced

1

How the test decides

Miller-Rabin writes n - 1 as 2^s times an odd number d, then computes a^d mod n and its successive squares. The number passes the round for base a if a^d is 1 mod n or one of those squares is n - 1; otherwise n is composite, with certainty. Each additional random base multiplies the chance of wrongly passing by at most 1/4.

2

Exact answers and generation

Below 3,474,749,660,383 the bases 2, 3, 5, 7, 11, 13, 17 are proven sufficient, so small inputs get an exact verdict, and the seven-base set 2, 325, 9375, 28178, 450775, 9780504, 1795265022 is verified exact for every number under 2^64. For generation, the tool draws random odd candidates of the requested bit length and retests until one passes; only about one in every 710 numbers near 2^1024 is prime.

Good uses

  • Checking p and q before combining them into an RSA modulus, or verifying a Diffie-Hellman group prime taken from a configuration file.
  • Generating a fresh random prime of a chosen size, 1024, 2048, or 3072 bits, as an ingredient for key generation.
  • Settling a number-theory question instantly: is 2^61 - 1 prime, or does a contest puzzle's 40-digit candidate actually pass?

Limits and checks

  • For large numbers, 'prime' is shorthand for 'no witness found'. With k rounds the worst-case error is 4^-k, so a 1024-bit verdict is right with overwhelming probability but is not a mathematical proof. Only results below the fixed-base bounds are exact; a result that does not state its round count is harder to trust.
  • A composite answer brings no factors. 561, a famous Carmichael number equal to 3 x 11 x 17 that fools Fermat-style tests, is still caught by Miller-Rabin, but the tool reports only 'composite'. Recovering p and q from an RSA modulus is factoring, a much harder problem the tool does not attempt.
  • A prime is not a finished key. It still needs a cryptographically secure random source and, for RSA, a modulus of at least 2048 bits (1024 is deprecated). Standards such as FIPS 186-5 also impose conditions on DSA and Diffie-Hellman primes, like the safe-prime form p = 2q + 1, which a bare generated prime may not satisfy.

Common questions

Why does it say 'probably prime' instead of just 'prime'?

For small numbers the test is exact and returns a plain verdict. Above a few trillion, no small fixed base set is proven, so the honest output is 'probably prime' with an error bound: k rounds cap the false-positive rate at 4^-k, and 20 rounds is about one in a trillion. Standards such as FIPS 186-5 accept this and specify how many rounds each bit length requires.

Can this tool factor a number or recover p and q?

No. Primality testing is a yes-or-no question and stays fast even for thousands of digits, whereas factoring is deliberately hard, which is exactly what RSA security rests on. The largest RSA modulus factored to date is RSA-250, a 250-digit number, and a 2048-bit modulus of 617 digits is far beyond known methods. For factors, use a dedicated factoring tool.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools