Every online secret rests on a problem being hard. Multiply primes in a blink and fail to undo it, then tour the five worlds we might be living in
Every padlock on the internet is a bet that some problem in NP is hard: not just in the worst case, but for nearly every instance, for as long as the secret matters. If P = NP, every one of those locks can be picked. If P ≠ NP, they still might be.
Slide the size of the primes up and watch multiplying stay instant while two factoring algorithms fall behind, then switch the chart out to 617 digits. Below, do the same with powers modulo a prime.
Sky: multiplying. Rose: trial division, which tries 2 and then every odd number, so it needs about √N / 2 divisions. Pink: Pollard’s rho, about 2.5 × N1/4 operations (three modular multiplications and a gcd per step). Dots are measured runs; amber marks the secret primes. The primes are random and pass a Miller–Rabin test. Each search is cut off after 3 seconds of computing, which trial division reaches at around 9 digits per prime and Pollard’s rho at around 14.
| bit | step | exponent so far | value |
|---|---|---|---|
| 1 | start | 1 | 2 |
| 0 | square | 2 | 4 |
| 1 | square, × base | 5 | 32 |
| 0 | square | 10 | 1024 |
| 1 | square, × base | 21 | 2097152 |
| 0 | square | 42 | 18819429 |
| 0 | square | 84 | 17879336 |
| 0 | square | 168 | 16869889 |
| 1 | square, × base | 337 | 29737455 |
| 1 | square, × base | 675 | 7847928 |
| 0 | square | 1350 | 21735378 |
| 0 | square | 2700 | 26017724 |
| 0 | square | 5400 | 17451596 |
| 1 | square, × base | 10801 | 26372826 |
| 1 | square, × base | 21603 | 7893554 |
| 0 | square | 43206 | 2986140 |
| 1 | square, × base | 86413 | 12010383 |
| 1 | square, × base | 172827 | 20231714 |
| 0 | square | 345654 | 17349679 |
| 1 | square, × base | 691309 | 26475829 |
| 0 | square | 1382618 | 30142163 |
| 1 | square, × base | 2765237 | 19930276 |
| 1 | square, × base | 5530475 | 24130110 |
| 0 | square | 11060950 | 6539192 |
| 0 | square | 22121900 | 12121952 |
Here p is a safe prime (p = 2q + 1 with q prime) and g is its smallest primitive root, so every remainder from 1 to p − 1 is a power of g exactly once. Baby-step giant-step (Daniel Shanks) writes x = i·m + j with m about √p: it tabulates gj for every j below m, then tries i = 0, 1, 2, … Amber marks the secret. The prime is capped at 12 digits, a table of a million entries.
A one-way function is a function that can be computed in polynomial time but that no polynomial-time algorithm, even one that flips coins, can invert on more than a negligible fraction of inputs. Inverting means finding any input that gives the right output. Multiplying two primes and raising a number to a power modulo a prime are the two classic candidates.
Nobody has proved that a one-way function exists. If P = NP, none does, because finding an input that produces a given output is a search problem whose answers are easy to check. So a proof that one exists would also prove P ≠ NP. The converse is not known: P ≠ NP says only that some instances of some problem are hard, and a one-way function needs a problem that is hard on almost every instance that can be generated. Hardness in the worst case is not hardness on average.
The two factoring algorithms in the demo are far from the best. The general number field sieve is sub-exponential: its running time grows faster than any polynomial in the number of digits but much more slowly than the square or fourth root of N. The largest RSA challenge number factored in public so far, RSA-250, has 829 bits and fell in 2020 after a very large computation. The dashed lines on the chart extrapolate two specific algorithms; they are not lower bounds on anything.
Factoring is not believed to be NP-complete. Phrased as a yes-or-no question (does N have a factor below k?), it lies in both NP and co-NP: a yes is certified by a factor, and a no by the complete prime factorisation of N, which can be checked because primality has short proofs. A problem in NP ∩ co-NP cannot be NP-complete unless NP = co-NP. See also: Between and Beyond.
Type a message and follow it through encryption and decryption with a small RSA key. Then choose an attacker: factor N by brute force, or ask an oracle a few dozen yes-or-no questions.
| division | remainder = s·(p − 1)(q − 1) + t·e |
|---|---|
| 21667992 = 1274587 × 17 + 13 | s = 1, t = −1274587 |
| 17 = 1 × 13 + 4 | s = −1, t = 1274588 |
| 13 = 3 × 4 + 1 | s = 4, t = −5098351 |
| 4 = 4 × 1 + 0 | s = −17, t = 21667992 |
| block | text | as a number m | sent: me mod N | received: cd mod N |
|---|---|---|---|---|
| “Mee” | 5072229 | 7422315 | 5072229 | |
| “t a” | 7610465 | 15667950 | 7610465 | |
| “t n” | 7610478 | 8403454 | 7610478 | |
| “oon” | 7303022 | 10182002 | 7303022 |
| bit | step | exponent so far | value |
|---|---|---|---|
| 1 | start | 1 | 5072229 |
| 0 | square | 2 | 6266773 |
| 0 | square | 4 | 19634414 |
| 0 | square | 8 | 14996205 |
| 1 | square, × base | 17 | 7422315 |
| bit | step | exponent so far | value |
|---|---|---|---|
| 1 | start | 1 | 7422315 |
| 1 | square, × base | 3 | 11365134 |
| 1 | square, × base | 7 | 7666657 |
| 1 | square, × base | 15 | 4410797 |
| 1 | square, × base | 31 | 1459758 |
| 1 | square, × base | 63 | 17818434 |
| 0 | square | 126 | 14115692 |
| 0 | square | 252 | 5917032 |
| 1 | square, × base | 505 | 10007604 |
| 1 | square, × base | 1011 | 3674795 |
| 0 | square | 2022 | 13645451 |
| 1 | square, × base | 4045 | 2700286 |
| 0 | square | 8090 | 3444512 |
| 1 | square, × base | 16181 | 15735277 |
| 0 | square | 32362 | 4097333 |
| 1 | square, × base | 64725 | 12348118 |
| 0 | square | 129450 | 15300787 |
| 0 | square | 258900 | 21326550 |
| 1 | square, × base | 517801 | 16363309 |
| 0 | square | 1035602 | 10016759 |
| 1 | square, × base | 2071205 | 17314897 |
| 0 | square | 4142410 | 6685390 |
| 0 | square | 8284820 | 9521734 |
| 1 | square, × base | 16569641 | 5072229 |
Amber: secrets. Sky: what is public. Rose: an attacker’s work. This is textbook RSA with tiny primes and no padding. It is insecure in other ways too: equal blocks encrypt to equal numbers, a short message with e = 3 can be read by taking an ordinary cube root, and with blocks this small an attacker could simply encrypt every possible block and compare. Real RSA uses primes of 300 digits or more and randomised padding. The demo is here to show the mathematics. Characters outside plain ASCII are sent as “?”.
Public-key cryptography was proposed by Whitfield Diffie and Martin Hellman in 1976: two people who have never met agree on a secret while an eavesdropper hears every word. The RSA system is due to Ron Rivest, Adi Shamir and Leonard Adleman (1977). Clifford Cocks had found an equivalent scheme at GCHQ in 1973; his work was declassified in 1997.
RSA works because (me)d leaves remainder m on division by N whenever e·d leaves remainder 1 on division by (p − 1)(q − 1). Anyone who can factor N can compute d, so breaking RSA is no harder than factoring. Whether it is as hard, that is, whether every way of reading RSA messages yields a way of factoring, is unknown.
Every cryptographic task asks the adversary to solve a problem in NP. Encryption, signatures, pseudorandom generators, commitments, zero-knowledge proofs: in each, the adversary may guess the key and check the guess. So all of them fall together if P = NP. The oracle in the demo makes this concrete. Its question has short certificates for yes, and binary search turns a decision procedure into the factor itself, the same search-from-decision trick that works for every NP-complete problem. See also: The Web of Reductions.
One-way functions turn out to be exactly the right assumption for much of cryptography. They are necessary and sufficient for private-key encryption, for pseudorandom generators (Johan Håstad, Russell Impagliazzo, Leonid Levin and Michael Luby, 1999) and for digital signatures. Public-key encryption seems to need more: nobody knows how to build it from an arbitrary one-way function, and every known scheme leans on a problem with special algebraic or geometric structure, such as factoring, discrete logarithms or lattices.
Visit each of the five islands and watch the board light up with what exists there. The two panels underneath measure the distinctions the worlds turn on.
The board restates Impagliazzo’s definitions and the known implications between them; it is not a measurement. The two panels below it are real computations, but small ones: 80 variables and 8 formulas per column say nothing about how hardness grows, and nobody has proved that random formulas at the threshold are hard on average. A formula that needs more than 3,000 branching steps is cut off and marked. Emerald dots are satisfiable formulas, rose ones are not. See also the Computational Complexity module for the whole phase transition.
Russell Impagliazzo described the five worlds in “A Personal View of Average-Case Complexity” (1995). Each is a consistent answer to a chain of open questions, and each is compatible with everything proved so far. The point of the map is that “P versus NP” is the coarsest question on it. Settling it in the expected direction would, roughly speaking, rule out Algorithmica and leave four worlds standing.
The second question, worst case against average case, has its own theory. Leonid Levin (1986) defined what it means for a problem with a distribution on its instances to be complete for average-case NP. The theory is harder to use than NP-completeness, and few natural problems are known to be complete in his sense. The third question separates “hard” from “usefully hard”: Pessiland has hard instances everywhere and no way to plant a secret in one.
Lattice problems are the main candidates for cryptography that would survive large quantum computers, and they are notable for another reason. Miklós Ajtai (1996) showed that for certain lattice problems, solving random instances is as hard as solving the worst instances of a related problem. That is a worst-case-to-average-case reduction, the kind of bridge that is missing for NP as a whole. See also: Would a Quantum Computer Help?
None of the five worlds has been ruled out. The islands in the demo are definitions and the implications between them, and the two measurements are small experiments. Neither is evidence about which world is ours.
Spot a mistake or have an idea?