Expected number of tries
Proven Prime number theorem (Hadamard, de la Vallée Poussin 1896): π(x) ~ x / ln x. A uniformly random odd b-bit number is prime with probability ≈ 2 / ln N, so the number of independent draws until a prime is geometric with mean E ≈ ln N / 2 = (b ln 2)/2 (the integral below averages over [2b−1, 2b)). After sieving by the odd primes up to 997, a fraction S of the odd numbers survives (Mertens: S ≈ 2e−γ/ln 997 ≈ 16.3%), so ≈ S · E candidates reach Miller-Rabin; the last one is the prime.
E[X] = 1 / ( 2 ∫12 du / ((b−1) ln 2 + ln u) ) ≈ ln N / 2 · S = ∏3≤p≤997 (1 − 1/p) =
A separate verification program checks these results: the formula agrees with exact prime counts for 16, 20 and 24 bits within 0.4%; 2000 forged 64-bit primes and 400 forged 256-bit primes have mean try counts within the expected statistical spread of the prediction; every forged prime is confirmed by the site's shared primality test.
Fermat, Carmichael, Miller-Rabin
Proven Fermat's little theorem; Korselt's criterion (1899); Alford-Granville-Pomerance (1994): C(x) > x2/7 for all large x, so there are infinitely many Carmichael numbers. Every Carmichael number has at least three prime factors.
n − 1 = d · 2s, d odd: ad ≡ 1 or ad·2r ≡ −1 (mod n) for some 0 ≤ r < s
Proven Monier (1980), Rabin (1980): an odd composite n > 9 has at most φ(n)/4 strong liars among 1 ≤ a ≤ n − 1. Hence k independent random bases err with probability ≤ 4−k. Deterministic bases: ψ1 = 2047, ψ2 = 1 373 653, ψ3 = 25 326 001, ψ4 = 3 215 031 751 (Pomerance-Selfridge-Wagstaff 1980), up to ψ8 by Jaeschke (1993), ψ9-ψ11 by Jiang-Deng (2014), ψ12, ψ13 by Sorenson-Webster (2017).
Conjecture Miller (1976): if the generalized Riemann hypothesis is true, testing all bases a ≤ 2 (ln n)2 (Bach's constant, 1990) is a deterministic polynomial-time test. GRH for Dirichlet L-functions was proven formally in Nov 2026 (Lean), so this test is now proven deterministic; a human-readable account and peer review are in progress.
What we checked by computer
Deterministic Miller-Rabin (13 bases) agrees with a sieve for every n ≤ 106. 43 Carmichael numbers below 106, 245 Fermat and 46 strong pseudoprimes to base 2. Strong liars ≤ φ(n)/4 for every odd composite 9 < n ≤ 104 (n = 9 has 2 of 6). The table values ψ1 … ψ13: factorizations and the fact that they fool the first k prime bases are verified; minimality is verified by search for ψ1-ψ3 and taken from the papers above for the rest.
A separate verification program checks the results. The forge draws candidates and Miller–Rabin bases from a cryptographically secure random source, sieves by the 167 odd primes below 1000, and runs in a Web Worker with JavaScript BigInt.
References
- J. Hadamard; C. de la Vallée Poussin (1896), the prime number theorem; see H. Davenport, Multiplicative Number Theory, Springer.
- A. Korselt, Problème chinois, L'Intermédiaire des Mathématiciens 6 (1899), 142-143.
- W. R. Alford, A. Granville, C. Pomerance, There are infinitely many Carmichael numbers, Annals of Math. 139 (1994), 703-722.
- G. L. Miller, Riemann's hypothesis and tests for primality, J. Comput. System Sci. 13 (1976), 300-317; E. Bach, Explicit bounds for primality testing and related problems, Math. Comp. 55 (1990), 355-380.
- M. O. Rabin, Probabilistic algorithm for testing primality, J. Number Theory 12 (1980), 128-138.
- L. Monier, Evaluation and comparison of two efficient probabilistic primality testing algorithms, Theoret. Comput. Sci. 12 (1980), 97-108.
- I. Damgård, P. Landrock, C. Pomerance, Average case error estimates for the strong probable prime test, Math. Comp. 61 (1993), 177-194.
- C. Pomerance, J. L. Selfridge, S. S. Wagstaff Jr., The pseudoprimes to 25 · 109, Math. Comp. 35 (1980), 1003-1026; R. Baillie, S. S. Wagstaff Jr., Lucas pseudoprimes, Math. Comp. 35 (1980), 1391-1417.
- G. Jaeschke, On strong pseudoprimes to several bases, Math. Comp. 61 (1993); Y. Jiang, Y. Deng, Strong pseudoprimes to the first eight prime bases, Math. Comp. 83 (2014); J. Sorenson, J. Webster, Strong pseudoprimes to twelve prime bases, Math. Comp. 86 (2017), 985-1003.
- M. Agrawal, N. Kayal, N. Saxena, PRIMES is in P, Annals of Math. 160 (2004), 781-793 (preprint 2002).
- S. Goldwasser, J. Kilian, Almost all primes can be quickly certified, STOC 1986; A. O. L. Atkin, F. Morain, Elliptic curves and primality proving, Math. Comp. 61 (1993), 29-68.
- NIST, FIPS 186-5, Digital Signature Standard (2023): how RSA primes are generated and tested in practice.
- A. K. Lenstra, J. P. Hughes, M. Augier, J. W. Bos, T. Kleinjung, C. Wachter, Ron was wrong, Whit is right, IACR ePrint 2012/064 (CRYPTO 2012).
- N. Heninger, Z. Durumeric, E. Wustrow, J. A. Halderman, Mining your Ps and Qs: detection of widespread weak keys in network devices, USENIX Security 2012.
- M. Nemec, M. Sys, P. Svenda, D. Klinec, V. Matyas, The return of Coppersmith's attack: practical factorization of widely used RSA moduli, ACM CCS 2017.
- OEIS A002997 (Carmichael numbers), A001567 (Fermat pseudoprimes to base 2), A001262 (strong pseudoprimes to base 2), A014233 (ψk).