2. What a quantum computer breaks

Draft

Factoring is period finding

Take the number 21 and write down the powers of 2, each reduced modulo 21: 1, 2, 4, 8, 16, 11, and then 1 again. The list repeats every six steps, and that six is enough to find the two primes whose product is 21, by arithmetic that can be checked by hand. Nothing in it is quantum. It is the classical half of the algorithm Peter Shor published in 1994.P. W. Shor, "Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer", SIAM Journal on Computing 26 (1997), pp. 1484 to 1509, arXiv quant-ph/9508027. A first version, "Algorithms for quantum computation: discrete logarithms and factoring", appeared at FOCS 1994. The same idea turns both problems that the keys of Section 1 rest on, factoring a product of two primes (RSA) and the discrete logarithm (Diffie-Hellman, on a clock or on a curve), into one problem: find a hidden period. A quantum computer finds periods. For a search with no structure to use, it gains only a square root. These two facts sort the cryptography in use today into what breaks and what survives.

N = 21, base a = 2: the powers of 2, each reduced modulo 21
x            0  1  2  3   4   5 | 6  7  8  9  10  11 | 12 ...
2^x mod 21   1  2  4  8  16  11 | 1  2  4  8  16  11 |  1 ...     one period (green): r = 6
halfway      2^3 mod 21 = 8, and (8 − 1)(8 + 1) = 63 = 3 × 21
factors      gcd(7, 21) = 7     gcd(9, 21) = 3     21 = 7 × 3

every base a from 2 to 19, by what its period gives
gives the factors               2  8  10  11  13  19              6
odd period: nothing             4  16                             2
halfway power = N − 1: nothing  5  17                             2
shares a factor with 21         3  6  7  9  12  14  15  18        8
at real size: for RSA-2048 the period has up to 617 digits, and no list of powers gets there
(the live figure needs JavaScript; it loads no data)
Factoring by period finding, in whole numbers that can be checked by hand. Green: one period of the powers of the base, from one 1 to the next. The ring marks the power halfway through it: its two neighbors each share a factor with N, and a greatest common divisor finds it. Below, every base in the row of what its period gives; the hatched rows give nothing. Choose N and a base (slider, tap or random draw); list the powers replays the search one multiplication at a time. Everything is exact arithmetic, done in the page.

The number to watch is the power halfway through the period, \(2^3 = 8\). Its square is \(1\) modulo \(21\), yet \(8\) itself is neither \(1\) nor \(20 \equiv -1 \pmod{21}\). Modulo a prime, \(1\) has only the two obvious square roots \(1\) and \(-1\); a third square root can exist only because \(21\) is composite, and it gives the prime factors away at once. Because \(21\) divides \(8^2 - 1 = (8 - 1)(8 + 1) = 7 \times 9\) without dividing either \(7\) or \(9\) alone, its prime factors must split between those two parentheses, where a greatest common divisor plucks each one out.

Definition 2.1.1 (the period). For \(a\) coprime to \(N\), the period of \(a\) modulo \(N\), also called its order, is the least \(r > 0\) with \(a^r \equiv 1 \pmod N\). The powers \(a^0, a^1, a^2, \dots\) modulo \(N\) repeat with exactly this period.

Whenever that period \(r\) is even, the halfway power \(x = a^{r/2} \bmod N\) satisfies \(x^2 = a^r \equiv 1 \pmod N\). It cannot equal \(+1\) modulo \(N\) because \(r\) is the first positive exponent that reaches \(1\); so as long as \(x\) avoids landing on \(-1\) as well, factoring \(x^2 - 1 = (x - 1)(x + 1)\) splits \(N\).

Proposition 2.1.2 (from a period to a factor). Let \(r\) be the period of \(a\) modulo \(N\). If \(r\) is even and \(a^{r/2} \not\equiv -1 \pmod N\), then \(\gcd(a^{r/2} - 1, N)\) and \(\gcd(a^{r/2} + 1, N)\) are proper factors of \(N\).

Proof. The modulus \(N\) divides \(a^r - 1 = (a^{r/2} - 1)(a^{r/2} + 1)\). It does not divide the first factor, because \(r\) is the least exponent with \(a^r \equiv 1\), nor the second, by assumption. A number that divides a product and neither of its factors has a proper divisor in common with each. ∎

Two bad cases can spoil a chosen base \(a\): an odd period \(r\) leaves no integer halfway exponent \(r/2\), and a halfway power \(a^{r/2} \equiv -1 \pmod N\) makes \(N\) divide \(a^{r/2} + 1\) outright so the greatest common divisors return only \(1\) and \(N\). Neither case blocks the algorithm, because whenever \(N\) is a product of two distinct odd primes, at least half of the bases coprime to \(N\) escape both.Write \(N = pq\). Modulo each of the two primes the powers of \(a\) move in a cyclic group of even size. Let \(2^d\) be the largest power of two that divides the period of \(a\) modulo \(p\), and \(2^e\) the same modulo \(q\). The proposition fails exactly when \(d = e\): when \(d = e = 0\) the period is odd; when \(d = e > 0\) the halfway power equals \(-1\) modulo both primes and hence modulo \(N\); whereas when \(d \ne e\) it equals \(1\) modulo one prime and \(-1\) modulo the other, which is neither \(1\) nor \(-1\) modulo \(N\). In a cyclic group of even size no value of \(d\) has probability greater than one half, and for a base drawn at random among those coprime to \(N\) its values modulo \(p\) and modulo \(q\) are independent, so \(d = e\) at most half of the time. A bad base costs only another random draw, and across all nine moduli in the figure the working bases at least match the failing ones. (A base that happens to share a prime factor with \(N\) surrenders it to \(\gcd(a, N)\) immediately, a windfall that vanishes at cryptographic sizes.)

Factoring \(N\) therefore reduces to five steps: draw a random base \(a < N\); check \(\gcd(a, N)\); find the period \(r\) of \(a\) modulo \(N\); if \(r\) is even and \(a^{r/2} \not\equiv -1 \pmod N\), compute \(\gcd(a^{r/2} \pm 1, N)\); otherwise draw a new base. Every step except finding \(r\) uses fast classical arithmetic (modular exponentiation from Section 1 and Euclid's algorithm) and needs no quantum hardware.S. J. Lomonaco Jr., "A lecture on Shor's quantum factoring algorithm", arXiv quant-ph/0010034 (2000), Section 3, sets the algorithm out as five steps, of which one needs a quantum computer. Finding \(r\) is the entire bottleneck. Modulo a 2,048-bit RSA integer \(N\), the period \(r\) can have nearly as many digits as \(N\) itself, so stepping through powers until \(1\) returns is hopeless, and no classical algorithm is known to find \(r\) faster than factoring \(N\) directly.

Yet recasting factoring as period finding changes the geometry of what has to be found. A prime factor is a lone needle hidden among exponentially many candidate divisors; a period is a global rhythm shared by every term of the sequence \(a^0, a^1, a^2, \dots \pmod N\). Wave interference struggles to isolate an unstructured needle (Section 2.6), whereas picking out a global rhythm is exactly what a quantum computer is built to do.

A register of amplitudes

A classical randomized register of \(n\) bits assigns each of its \(2^n\) possible bit strings \(x\) a nonnegative probability \(p_x\) summing to \(1\); if two execution paths lead to the same string \(x\), their probabilities can only add, never subtract. A quantum register of \(n\) qubits instead assigns each \(n\)-bit string \(x\) a complex number \(\alpha_x\), its amplitude, whose squared magnitude \(\lvert \alpha_x \rvert^2\) gives the probability of observing \(x\) upon measurement. Because complex amplitudes can carry opposite signs or phases, two paths arriving at the same string \(x\) add before squaring and can cancel each other out.

Quantum gates transform that list of \(2^n\) amplitudes linearly. Shor's algorithm begins with the Hadamard gate on a single qubit q: for every pair of basis indices i and j that agree everywhere except in bit q (where i has 0 and j has 1), it replaces their amplitudes \((\alpha_i, \alpha_j)\) with their normalized sum and difference, introducing a minus sign on the 1 branch. Here is how the state-vector simulator in this page applies the Hadamard gate to real and imaginary arrays re and im:

var re = state.re, im = state.im, bit = 1 << q;
for (var i = 0; i < state.size; i++) {
  if (i & bit) continue;
  var j = i | bit;
  var ar = re[i], ai = im[i], br = re[j], bi = im[j];
  re[i] = (ar + br) * SQRT1_2; im[i] = (ai + bi) * SQRT1_2;
  re[j] = (ar - br) * SQRT1_2; im[j] = (ai - bi) * SQRT1_2;
}

Simulating that gate in JavaScript requires looping over all \(2^n\) entries of state. On a physical quantum processor, it is a single operation addressed to qubit q that updates all \(2^{n-1}\) amplitude pairs at once.

Example 2.2.1 (a coin that comes back). Take a single qubit, whose state is a pair of amplitudes \((\alpha_0, \alpha_1)\), and apply the Hadamard gate twice starting from \((1, 0)\) (the qubit definitely reads 0). After the first gate, the state is \((1/\sqrt 2, 1/\sqrt 2) \approx (0.707, 0.707)\); measuring halfway through would return 0 or 1 with probability \(\tfrac12\) each, just like a fair coin. Instead of measuring, apply the Hadamard gate a second time. For outcome 0, the two branches contribute \(+\tfrac12\) (via 0) and \(+\tfrac12\) (via 1), summing to \(1\); for outcome 1, they contribute \(+\tfrac12\) (via 0) and \(-\tfrac12\) (via 1), canceling to \(0\). The state returns to \((1, 0)\), and the qubit reads 0 with certainty.The example is from S. Aaronson, "Quantum Computing Since Democritus" (lecture course PHYS771, 2006), Lecture 9, "Quantum", where it is told with a rotation in place of this gate. No classical randomized step behaves like this: once a noisy step turns heads into a fair coin toss, applying the same noisy step again cannot restore heads for certain, because classical probabilities add and never cancel. ◁

Generalizing from one qubit to \(n\) qubits gives the whole computational model in three rules. First, the state of \(n\) qubits is a vector of \(2^n\) complex amplitudes \(\alpha_x\) satisfying \(\sum_x \lvert \alpha_x \rvert^2 = 1\). Second, every gate applies a linear map that preserves that unit sum (a unitary matrix), built from elementary gates acting on one or two qubits at a time. Third, measuring the register collapses the state: it returns a single \(n\)-bit value \(x\) with probability \(\lvert \alpha_x \rvert^2\) and leaves the register holding \(x\) alone, erasing all other amplitudes. (Reading only a subset of the qubits returns one outcome on those qubits and zeroes out every amplitude inconsistent with it, rescaling the surviving consistent amplitudes so their squared magnitudes again sum to \(1\).) Because amplitudes for the same outcome add before they are squared, constructive and destructive interference is a quantum algorithm's sole resource: the art is arranging gates so that paths leading to wrong answers cancel while paths leading to informative answers reinforce.

Remark 2.2.2 (not every answer at once). Applying a Hadamard gate to each of \(n\) zeroed qubits gives all \(2^n\) inputs \(x\) equal amplitude \(1/\sqrt{2^n}\), and running a reversible circuit for a function \(f\) once on that register produces an equal superposition of all \(2^n\) pairs \((x, f(x))\). Popular accounts often stop right there, suggesting that the machine has tried every input in parallel and need only read off the winner. Measuring that superposition, however, collapses the register to one pair \((x, f(x))\) for a uniformly random \(x\) (probability \(1/2^n\) each) and destroys the other \(2^n - 1\) evaluations permanently; an ordinary laptop achieves the exact same thing by picking one random \(x\) and evaluating \(f(x)\) once. Quantum computation helps only when further gates make those \(2^n\) amplitudes interfere before measurement, and interference reveals a global pattern shared across the outputs far more readily than it singles out one special input (Section 2.6).

Scott Aaronson puts that trap bluntly:

Alright, so let’s say you want to break the RSA cryptosystem, in order to rob some banks, read your ex’s email, whatever. We all know that breaking RSA reduces to finding the prime factors of a large integer N. Unfortunately, we also know that “trying all possible divisors in parallel,” and then instantly picking the right one, isn’t going to work. Hundreds of popular magazine articles notwithstanding, trying everything in parallel just isn’t the sort of thing that a quantum computer can do. Sure, in some sense you can “try all possible divisors” — but if you then measure the outcome, you’ll get a random divisor, which almost certainly won’t be the one you want.

—Scott Aaronson, "Shor, I'll do it" (2007). An essay on his blog, Shtetl-Optimized, of 24 February 2007 (scottaaronson.blog/?p=208), second paragraph. In a comment under it, Shor called it the best explanation of quantum computing for a general reader that he had seen.

The Fourier transform turns equal spacing into peaks

To extract the period of \(7^x \bmod 15\) (whose values \(1, 7, 4, 13, 1, 7, \dots\) repeat every \(r = 4\) steps), prepare an 8-qubit first register holding all \(Q = 256\) exponents \(x \in \{0, \dots, 255\}\) at equal amplitude, compute \(7^x \bmod 15\) reversibly into a 4-qubit second register beside it, and read only the second register. Suppose that reading randomly returns \(13\). Every exponent whose remainder was \(1\), \(7\), or \(4\) vanishes, leaving the first register in an equal superposition of the 64 exponents with \(7^x \equiv 13 \pmod{15}\): namely \(x = 3, 7, 11, 15, \dots, 255\). Those surviving amplitudes form a periodic comb whose teeth stand \(r = 4\) apart, shifted by an unpredictable starting offset \(x_0 = 3\) (had the second register returned \(4\) instead, the comb would have started at \(x_0 = 2\)). Measuring the first register right now would collapse the comb to one random tooth \(x_0 + jr\) for an unknown offset \(x_0\) and an unknown multiple \(j\), yielding a single featureless integer between \(0\) and \(255\) that reveals nothing about \(r\). A unitary transformation has to act before measurement to wipe out the random shift \(x_0\) and turn the tooth spacing \(r\) into sharp peaks.

N = 15, base 7: registers of 8 + 4 = 12 qubits, 4,096 amplitudes; the first holds x = 0 .. 255 (Q = 256)
stages   start, superposition, modular exponentiation, measure 2nd register, Fourier transform,
         measure 1st register, continued fractions

before   2nd register measured: 13. Left: the x with 7^x mod 15 = 13
         x = 3, 7, 11, 15, ...       64 teeth, one every r = 4
after    the Fourier transform (green): 4 peaks, Q/r = 256/4 = 64 apart, probability 0.250 each
         c     0    64    128   192
         c/Q   0    1/4   1/2   3/4      1/4 and 3/4 give r = 4
why      a tooth adds an arrow turned r c/Q of a turn: at c = 64, 1 turn, 64 arrows in step;
         at c = 65, 1.0156 turns, a closed loop
end      measured 64; 64/256 = [0; 4]; r = 4; 15 = 3 × 5. One run finds r with probability 0.500
runs     47 recorded on one GPU, 12 to 31 qubits: from 26 qubits up the time grows 2.09 times a qubit;
         13 of 42 with a random base found the factors; largest: 1,003 = 17 × 59, 31 qubits, 17.2 GB,
         9.76 s; 32 qubits need 34.4 GB, the GPU has 33.7 GB
at real size: RSA-2048 would take 6,144 qubits in this layout
(the live figure needs JavaScript and loads about 0.1 MB of data)
Shor's order finding on a simulated register, run in the page. Ink: the first register before the Fourier transform. Green: after it, the probability standing on the multiples of Q/r; hairline hands are phases. Step through the stages, or run; point at a value below to see its arrows add, one a tooth. The strip holds recorded runs of the same algorithm on one GPU, where each further qubit doubles the time: an ideal, noiseless machine with no error correction, the modular exponentiation applied as a permutation. Its time says what simulating costs, not what running on hardware would.

The quantum Fourier transform solves both problems by adding rotated unit arrows in the complex plane. For each candidate frequency index \(c \in \{0, \dots, Q - 1\}\), it assigns each input \(x\) an arrow turned by \(x c / Q\) of a full revolution and sums the arrows contributed by all 64 teeth \(x = x_0, x_0 + r, x_0 + 2r, \dots\) of the comb. Stepping from one tooth to the next increases \(x\) by \(r\), turning the next arrow by an extra \(r c / Q\) of a full circle. Whenever \(c\) is an exact multiple of \(Q/r\) (here \(c = 0, 64, 128, 192\), since \(256/4 = 64\)), \(r c / Q\) is a whole number of full turns: all 64 arrows point in the exact same direction and add end to end into a tall peak, while changing the random offset \(x_0\) merely rotates the entire bundle together without altering its length. At an off-peak index such as \(c = 65\), each step turns the arrow by \(1 + 1/64\) revolutions, fanning the 64 arrows evenly around the circle in a closed polygon that cancels to zero.

Scott Aaronson pictures that interference through a wall of custom analog clocks:

Now, though, I want you to imagine that my bedroom wall is covered with analog clocks. These are very strange clocks: one of them makes a full revolution every 17 hours, one of them every 26 hours, one of them every 24.7 hours, and so on for just about every number of hours you can imagine. (For simplicity, each clock has only an hour hand, no minute hand.) I also want you to imagine that beneath each clock is a posterboard with a thumbtack in it. When I first moved into my apartment, each thumbtack was in the middle of its respective board. But now, whenever I wake up in the “morning,” the first thing I do is to go around my room, and move each thumbtack exactly one inch in the direction that the clock hand above it is pointing.

—Scott Aaronson, "Shor, I'll do it" (2007). The same essay, further down; the paragraphs that follow it there let the thumbtacks answer.

If the room's occupant keeps a 26-hour day, the thumbtack beneath the 24-hour clock gets nudged at a shifting angle each morning and wanders near the center, its steps canceling over the weeks, while the thumbtack beneath the 26-hour clock is pushed in the exact same direction every morning and walks straight off its board. The waking mornings are the teeth of the comb, each clock tests a candidate frequency \(c/Q\), and the thumbtacks that travel farthest mark multiples of \(1/r\).

In symbols (writing \(e^{2\pi i \theta}\) for the unit arrow turned by \(\theta\) of a full circle), the quantum Fourier transform maps the amplitudes \(\alpha_x\) of a register of \(Q = 2^t\) states to

\[\beta_c \;=\; \frac{1}{\sqrt{Q}} \sum_{x=0}^{Q-1} e^{2\pi i\, x c / Q}\, \alpha_x , \tag{2.1}\]

the discrete Fourier transform of the amplitude vector. Evaluating (2.1) on a comb of \(M\) equally spaced teeth at \(x_0, x_0 + r, x_0 + 2r, \dots\), each carrying amplitude \(1/\sqrt{M}\), factors the offset \(x_0\) in front of a finite geometric series:

\[\begin{aligned} \beta_c &= \frac{e^{2\pi i\, x_0 c/Q}}{\sqrt{QM}} \sum_{j=0}^{M-1} e^{2\pi i\, j\, r c/Q}, \\ \lvert \beta_c \rvert^2 &= \frac{1}{QM}\, \frac{\sin^2(\pi M r c/Q)}{\sin^2(\pi r c/Q)} . \end{aligned} \tag{2.2}\]

Because \(\lvert e^{2\pi i\, x_0 c / Q} \rvert = 1\), squaring the magnitude erases \(x_0\) completely. When \(r\) divides \(Q\) evenly, as \(4\) divides \(256\), \(\lvert \beta_c \rvert^2\) equals \(1/r\) at each of the \(r\) multiples of \(Q/r\) (where the ratio of squared sines reaches its limit \(M^2\)) and zero everywhere else. When \(r\) does not divide \(Q\), the peaks acquire a narrow width around the non-integer multiples \(sQ/r\), and the single integers nearest to those multiples still capture at least \(4/\pi^2 \approx 0.41\) of the total probability between them.J. Preskill, "Lecture notes for Physics 229: Quantum Information and Computation", Chapter 6, "Quantum Computation" (Caltech, 1998), Section 6.9.1, pp. 68 to 71, which (2.1) and (2.2) follow.

The order of the two operations is the point. Preskill's lecture notes say so at the moment the comb is ready:

Now our task is to extract the value of r from the state eq. (6.197) that we have prepared. Were we to measure the input register by projecting onto the computational basis at this point, we would learn nothing about r. Instead (cf. Simon’s algorithm), we should Fourier transform first and then measure.

—J. Preskill, lecture notes on quantum computation (1998). Chapter 6, Section 6.9.1, p. 69. Equation (6.197) of the notes is the comb, and the next paragraph applies the transform to it; Simon's problem, treated earlier in the chapter, is another search for the period of a function. The notes add that the comb need not be made by a measurement at all: leaving the second register unread gives the same result.

What turns (2.1) into a viable algorithm is how cheaply it compiles into quantum gates. On a classical computer, a fast Fourier transform on \(Q = 2^t\) numbers takes roughly \(Q \log_2 Q\) operations, which is impossible when \(Q\) has more than 1,200 decimal digits (as a 2,048-bit RSA modulus requires). On a \(k\)-qubit register, the phase \(e^{2\pi i\, x c / 2^k}\) splits across the individual bits of \(c\), factoring the entire transform into single-qubit Hadamard gates H (from Section 2.2) and two-qubit controlled-phase gates CP that rotate the phase by \(\pi/2^{j-l}\) whenever qubits j and l both read 1:

for (j = k - 1; j >= 0; j--) {                     // the most significant qubit first
  H(j);
  for (l = j - 1; l >= 0; l--) CP(j, l, +1);
}
swapAll();

Across k qubits, that loop uses one Hadamard gate per qubit and one controlled-phase gate per pair of qubits, \(k(k+1)/2\) gates in all (36 gates on the 8 qubits here), followed by bit-reversal swaps. Compressing a transform over \(2^t\) amplitudes into roughly \(t^2/2\) gates is what Preskill's notes call the key idea of quantum period finding, credited to Shor.

Shor's algorithm, end to end

Measuring the first register ends the quantum part of the algorithm; everything after it is fast classical post-processing. Most of the time, the measured integer \(c\) lands either right on a multiple \(sQ/r\) (for some random peak index \(s \in \{0, \dots, r - 1\}\)) or on an integer immediately adjacent to one. When \(r\) happens to divide \(Q\) evenly, dividing \(c\) by \(Q\) gives the reduced fraction \(s/r\) directly: in the opening run on \(N = 15\), measuring \(c = 64\) with \(Q = 256\) gives \(64/256 = 1/4\), whose denominator reveals \(r = 4\).

When \(r\) does not divide \(Q = 2^t\), the measured integer \(c\) sits within \(\tfrac12\) of \(sQ/r\), so the known binary fraction \(c/Q\) only approximates the unknown fraction \(s/r\) within \(1/(2Q)\), and plain cancellation of common factors cannot uncover \(r\). Any two distinct fractions with denominators below \(N\), however, stand apart on the number line by at least \(1/N^2\) (since \(\lvert s/r - s'/r' \rvert \ge 1/(rr') > 1/N^2\)). Sizing the first register so that \(Q \ge N^2\), roughly twice as many qubits as \(N\) has bits, ensures that at most one fraction with denominator below \(N\) can lie within \(1/(2Q)\) of \(c/Q\). The classical continued-fraction expansion finds that fraction directly: by repeatedly taking reciprocals and peeling off integer parts, just like Euclid's algorithm, it produces a short sequence of convergents (the closest rational approximations to \(c/Q\) with growing denominators), and one modular exponentiation tests whether each denominator below \(N\) is a period.

Example 2.4.1 (a period that does not divide the register). Factor \(N = 21\) with base \(2\), whose period is \(r = 6\) (Section 2.1), using \(9 + 5 = 14\) qubits so that \(Q = 2^9 = 512 > 21^2\) and the Fourier peaks sit near multiples of \(512/6 \approx 85.33\). Suppose the measurement returns \(c = 85\). Although \(85/512\) is already in lowest terms, expanding it by repeated reciprocals gives \(85/512 = 1/(6 + 1/(42 + 1/2))\), and truncating after each term yields the convergents \(0/1\), \(1/6\), \(42/253\), and \(85/512\). Testing denominators below \(21\) checks \(2^6 \bmod 21 = 1\), recovering \(r = 6\). Suppose instead that the measurement returns \(171\), next to \(2 \cdot 85.33\). Because \(s/r = 2/6\) reduces to \(1/3\) in lowest terms, the convergents of \(171/512\) with denominators below \(21\) are \(0/1\), \(1/2\), and \(1/3\). Neither \(2\) nor \(3\) satisfies \(2^q \equiv 1 \pmod{21}\), so this run detects its failure and must be repeated. ◁

In the page's code, periodFromMeasurement walks through the convergents of \(c/Q\) with denominator below \(N\) and checks each candidate with modPow:

function periodFromMeasurement(c, Q, N, a) {
  var list = [], period = null, all = convergents(c, Q);
  for (var k = 0; k < all.length && all[k].q < N; k++) {
    var isPeriod = all[k].q > 0 && modPow(a, all[k].q, N) === 1;
    list.push({ p: all[k].p, q: all[k].q, isPeriod: isPeriod });
    if (isPeriod) { period = all[k].q; break; }
  }
  return { period: period, convergents: list };
}

So a run can fail, and often does. The measurement lands near \(sQ/r\) for an \(s\) from 0 to \(r - 1\) that nobody controls, and it reveals \(r\) only when \(s\) and \(r\) have no common factor; the base may also be one of those that Proposition 2.1.2 excludes. On 15 with base 7 a single run finds the period with probability exactly 0.500, on 21 with base 2 with probability 0.328. No failure is silent, since the candidate is tested by one modular power, and a failed run is repeated. Two runs can also be combined: when their two values of \(s\) have no common factor, the least common multiple of the two denominators is \(r\), which for large \(r\) happens with probability about \(6/\pi^2 \approx 0.61\).Preskill, Section 6.9.1, p. 71: two numbers drawn at random have no common factor with probability \(6/\pi^2\). The runs here are each read alone, so their failures show.

How large a number can be factored this way without the machine? The register has to hold \(Q \ge N^2\) values of \(x\) and, beside them, a number below \(N\): 12 qubits for 15, and 18 for 63, where the page stops. Every further qubit doubles the list of amplitudes. The same algorithm was run on a graphics card (GPU) with the whole list in its memory, 47 runs on 12 to 31 qubits. Up to about 21 qubits a run takes a few milliseconds of launch overhead, whatever its size; from 26 qubits up, where the growth was fitted by least squares, each further qubit multiplied the time by 2.09. The largest number factored with a base drawn at random was \(1{,}003 = 17 \times 59\), with base 298 on 31 qubits: a list of 17.2 GB and 9.76 seconds, in a single run. A 32nd qubit needs 34.4 GB, and the card has 33.7 GB. Of the 42 runs whose base was drawn at random, 13 found the factors. Of the other 29, 26 drew an \(s\) that is zero or shares a factor with \(r\), and three drew a base that Proposition 2.1.2 excludes.

None of these timings measure a quantum computer. The simulated register is noiseless, omits error correction, and shortcuts modular exponentiation by permuting the state array directly (one modular multiplication per qubit of the first register), whereas physical hardware must build each multiplication out of a deep circuit of elementary gates and scratchpad qubits. The GPU timings measure the exponential cost of classical simulation, which doubles with every added qubit, whereas on an actual quantum processor the gate count grows only polynomially in the bit length of \(N\): that polynomial scaling is the central result of Shor's paper. As a classical factoring method, state-vector simulation loses to the crudest trial division: dividing \(1{,}003\) by \(2, 3, 4, \dots\) finds \(17\) in under a microsecond on one CPU core, roughly ten million times faster. Factoring a 2,048-bit RSA modulus in this layout would take 6,144 qubits, a vector of \(2^{6144}\) complex amplitudes that no classical memory could ever hold. Whether physical hardware can run it instead is the question of Section 2.7.

Discrete logarithms fall the same way

At first glance, the discrete logarithm problem of Section 1 displays no repeating sequence: the secret exponent \(a\) sits inside a single public power \(A = g^a\). As Section 1 closed by noting, the hidden period appears as soon as two exponents vary together.

Example 2.5.1 (a logarithm as a period). Take the 23-hour clock of Section 1 with base \(g = 5\) and public key \(8 = 5^6 \bmod 23\), hiding the private exponent \(6\). From the public values \(5\) and \(8\) alone, anyone can evaluate \(f(u, v) = 5^u \cdot 8^{-v} \bmod 23\). Because \(8 = 5^6\), this function equals \(5^{u - 6v} \bmod 23\), so \(f(u + 6, v + 1) = f(u, v)\) for every pair \((u, v)\); for example, \(f(6, 1) = 8 \cdot 8^{-1} \equiv 1 = f(0, 0)\). The function repeats along the two-dimensional step \((6, 1)\), whose first coordinate is the private key. ◁

Shor's 1994 paper solves discrete logarithms with the same Fourier machinery. Two input registers hold superpositions of \(u\) and \(v\), a third register computes \(f(u, v)\) beside them, and a separate quantum Fourier transform acts on each input register. Stepping from \((u, v)\) to \((u + 6, v + 1)\) turns the combined Fourier arrow at output pair \((c, d)\) by \((6c + d)/22\) of a full circle, so constructive interference concentrates probability on pairs \((c, d)\) satisfying \(6c + d \equiv 0 \pmod{22}\) (up to the rounding of Section 2.4 when the group order is not a power of two). Measuring a pair such as \((1, 16)\), where \(16 \equiv -6 \cdot 1 \pmod{22}\), yields the secret \(6\) in a single modular division.

Nothing in that circuit uses any property of integers modulo 23 beyond the group operation itself. Replace clock multiplication with point addition on an elliptic curve, evaluating \(f(u, v) = uG - vP\) for a public point \(P = kG\), and the exact same two-dimensional period \((k, 1)\) emerges. Section 1 explained why elliptic-curve keys can be ten times shorter than RSA keys against classical computers: curves lack prime factorization, forcing classical attackers back to generic group searches. Quantum period finding needs nothing except the group law. Moving to an elliptic curve therefore buys zero quantum resistance, and its compact keys actually make the quantum circuit smaller, since the input registers hold 256-bit scalars where RSA of comparable classical strength requires 3,072-bit integers.

In the count of Roetteler, Naehrig, Svore and Lauter (2017), a 256-bit curve takes 2,330 logical qubits and a 3,072-bit RSA modulus 6,146.M. Roetteler, M. Naehrig, K. Svore and K. Lauter, "Quantum resource estimates for computing elliptic curve discrete logarithms", ASIACRYPT 2017 (arXiv 1706.06752), Table 2. Their conclusion: at comparable classical strength, curves are the easier target. A logical qubit is an ideal, error-free qubit like the simulated ones; Section 2.7 says what one costs. An estimate posted in March 2026 puts a 256-bit curve at no more than 1,200 logical qubits and 90 million Toffoli gates, the three-qubit gates in which such estimates count their work.R. Babbush and others (Google Quantum AI), "Securing elliptic curve cryptocurrencies against quantum vulnerabilities: resource estimates and mitigations", arXiv 2603.28846, March 2026, abstract, for the curve secp256k1; an alternative circuit has 1,450 logical qubits and 70 million Toffoli gates. It is a preprint, its circuits are withheld, and a zero-knowledge proof, a proof meant to convince its reader that such circuits exist without showing them, stands in for them.

So every public key of Section 1 falls to one idea: RSA by the period of Section 2.1, Diffie-Hellman and X25519, its form on a curve, by this one, and with them the signatures built on the same two problems.

Search gets only a square root

Once a key is agreed, the traffic itself is encrypted with a symmetric cipher, one where both sides hold the same key; the standard one is AES, the Advanced Encryption Standard. Breaking it at its shortest key length, 128 bits, means finding one key among \(2^{128}\), and nothing is known to do with a candidate but to try it: no period, and nothing that the wrong keys have in common except being wrong. For search of this kind, with no structure, L. K. Grover gave a quantum algorithm in 1996.L. K. Grover, "A fast quantum mechanical algorithm for database search", STOC 1996, pp. 212 to 219 (arXiv quant-ph/9605043). It gains a square root, and no more.

16 items on 4 qubits, item 12 marked. A step: the oracle flips the sign of the marked item,
then every amplitude is reflected about the mean
steps k            0      1      2      3      4      5      6
marked amplitude   0.250  0.688  0.953  0.980  0.763  0.354  −0.143
chance of reading  0.063  0.473  0.908  0.961  0.582  0.125  0.020
best: 3 steps, near (π/4)√16 = 3.14; after that, more steps make it worse

items    2^4  2^5  2^6  2^7  2^8  2^9  2^10  2^11  2^12  2^13  2^14  2^15  2^16
best k    3    4    6    8   12   17    25    35    50    71   100   142   201
four times the items, twice the steps: a square root
among 65,536 items: 201 steps, against 32,768 looks on average when they are checked one by one
a 128-bit key: about 1.4 × 10^19 steps in a row (2^64 × π/4); a 256-bit key: about 2.7 × 10^38 (2^128 × π/4)
(the live figure needs JavaScript; it loads no data)
Grover's search on a simulated register. Green: the marked item, a bar among the amplitudes and a dot on its curve. Each step flips its sign, then reflects every amplitude about the mean (dashed); outlines show the half-step before. The curves give the chance of reading the marked item for 2⁴ to 2¹⁶ items: each peaks near (π/4)√N steps, then falls (hatched). Dashed, on the right: the same items checked one by one. Scrub or play the steps, choose 16, 32 or 64 items, tap a bar to mark it. Bars: simulated in the page; curves: the exact formula.

Each iteration of Grover's algorithm performs two operations on a uniform superposition of \(N\) items (in this section \(N\) counts the search space, not an integer to factor): first, an oracle circuit recognizes the target item and flips the sign of its amplitude without knowing where it sits (in a key search, that oracle runs the block cipher once across the superposition and checks whether the output matches known ciphertext); second, a diffusion circuit reflects every amplitude across the average of all \(N\) amplitudes. On the 16-item register in the figure, every bar begins at \(1/\sqrt{16} = 0.250\). Flipping the marked item to \(-0.250\) nudges the mean down slightly to \(0.219\), and reflecting every bar across \(0.219\) drops the 15 unmarked bars slightly while lifting the marked bar from \(-0.250\) up to \(2(0.219) - (-0.250) = 0.688\). In general, with \(\sin\theta = 1/\sqrt N\), each iteration rotates the state vector toward the marked item by \(2\theta \approx 2/\sqrt N\) radians, reaching amplitude \(\sin((2k+1)\theta)\) after \(k\) steps. Reaching probability near \(1\) therefore takes about \((\pi/4)\sqrt N\) serial steps, and running past that peak rotates the hand beyond vertical and drives the success probability back down.

For a symmetric key of \(b\) bits (\(N = 2^b\)), Grover's algorithm requires \((\pi/4)\,2^{b/2}\) sequential cipher evaluations: the exponent is halved rather than eliminated. Searching a 128-bit key takes roughly \(1.4 \times 10^{19}\) steps one after another, and searching a 256-bit key takes roughly \(2.7 \times 10^{38}\) steps, comparable to classical brute force on 128 bits. Doubling the key length restores every bit of security that Grover's speedup shaved off. Nor is a faster unstructured quantum search waiting to be discovered: Grover's square-root bound is proved optimal up to a small constant factor for black-box search (though that AES offers no algebraic shortcut past black-box search remains, as everywhere in cryptanalysis, an empirical judgment).

NIST, the United States National Institute of Standards and Technology, whose standards the rest of the series follows, drew the conclusion in a report of April 2016, months before it called for proposals:

The most important uses of public key cryptography today are for digital signatures and key establishment. As mentioned in Section 1, the construction of a large-scale quantum computer would render many of these public key cryptosystems insecure. In particular, this includes those based on the difficulty of integer factorization, such as RSA, as well as ones based on the hardness of the discrete log problem. In contrast, the impact on symmetric key systems will not be as drastic (see Table 1). Grover’s algorithm provides a quadratic speed-up for quantum search algorithms in comparison with search algorithms on classical computers. We don’t know that Grover’s algorithm will ever be practically relevant, but if it is, doubling the key size will be sufficient to preserve security. Furthermore, it has been shown that an exponential speed up for search algorithms is impossible, suggesting that symmetric algorithms and hash functions should be usable in a quantum era [3].

—NIST, Report on Post-Quantum Cryptography, NISTIR 8105 (2016). Section 2, p. 3, of the report; "Section 1" and "Table 1" are its own. Its Table 1, on p. 2, lists AES as needing larger keys, the hash functions SHA-2 and SHA-3 as needing larger outputs, and RSA, the curve schemes ECDSA and ECDH, and DSA, the signature scheme on the discrete logarithm modulo a prime, as no longer secure.

Its position has since moved further the same way. A long serial computation is hard to run, and an attacker who divides the search among many machines loses part of the square root: NIST's call for proposals of 2016 notes that in a realistic attack "one has to run many smaller instances of the algorithm in parallel, which makes the quantum speedup less dramatic", and its page of frequently asked questions, as it stood on 30 November 2026, holds that "it is quite likely that Grover’s algorithm will provide little or no advantage in attacking AES, and AES 128 will remain secure for decades to come".NIST, "Submission Requirements and Evaluation Criteria for the Post-Quantum Cryptography Standardization Process" (the call for proposals, December 2016), Section 4.A.5, p. 18; NIST, "Post-Quantum Cryptography FAQs", csrc.nist.gov, read on 30 November 2026. These ciphers are even the yardstick for their replacements: of the five security categories in which NIST places the new schemes, three are defined by them, category 1 meaning at least as hard to break as finding a key of AES-128, and the other two by a hash function, which reduces an input of any length to a short digest of fixed length (Section 1.6). Hash functions stand with the ciphers, which is why the most conservative signatures of the series are built from a hash function and nothing else (Section 8).

Factoring and the discrete logarithm each hide a period, and a quantum Fourier transform makes a period visible: that takes every public key of Section 1. A search without structure gains only a square root, which a key twice as long takes back.

What a quantum computer breaks, and what survivesa row to a problem: what rests on it today, and in ink what a quantum computer does to it

  1. 2.1factoring RSA

    The powers of a base modulo N repeat, and their period gives the factors of N by two greatest common divisors. A quantum Fourier transform makes the period visible.

    breaks

    a period to find

  2. 2.5discrete logarithm modulo a prime Diffie-Hellman, DSA

    The private exponent is the step of a period in two directions, in a function anyone can compute from the public values. The same transform finds it.

    breaks

    a period in two directions

  3. 2.5discrete logarithm on a curve X25519, ECDSA

    Period finding asks for nothing but the group law, so a curve protects nothing here, and its short keys become a weakness.

    breaks, with fewer qubits

    2,330 logical qubits for a 256-bit curve

    6,146 for RSA of equal classical strength

  4. 2.6key search AES

    No period, and nothing is known to do with a candidate key but to try it. Grover's search gains a square root, in steps that run one after another, and for a search without structure no quantum algorithm gains more.

    survives

    a key twice as long takes the square root back

  5. 2.6hash functions SHA-2, SHA-3

    They stand with the ciphers: NIST lists larger outputs as the remedy. The most conservative signatures of the series are built from a hash function and nothing else.

    survive

    with larger outputs

green: broken by period finding

How big a machine, and why move before it exists

The registers so far never made an error. Physical qubits do: the published designs typically assume one faulty operation in a thousand, and a run of Shor's algorithm at real size lasts hours to months. So each qubit of the algorithm, a logical qubit, is spread over many physical ones by an error-correcting code, which detects errors and undoes them while the computation runs. The leading code for a flat grid of qubits that each talk only to their neighbors is the surface code. How many physical qubits a logical one costs depends on the code, the error rate and the speed of the hardware, so the question of how many qubits break RSA has two answers: a few thousand logical qubits, and a number of physical qubits that is an estimate about a machine nobody has built.

physical qubits needed to factor a 2,048-bit RSA modulus, by date of the estimate (green), with its run time
2012   1,000,000,000   1.1 days       surface code on a grid     Fowler et al.
2019      20,000,000   8 hours        surface code on a grid     Gidney and Ekera
2021          13,436   177 days       color codes + a memory     Gouzien and Sangouard
2025         897,864   4.96 days      surface code on a grid     Gidney: "enough" is hatched from here
2026         100,000   30 days        LDPC codes                 Webster et al.
2026          11,000   no single one  neutral atoms              Cain et al.
2026         500,000   no single one  neutral atoms              Xue and Covey
2026          22,593   3.14 days      cat qubits                 Pappalardo et al.
one design, 2012 to 2025: about 1,100 times fewer; 7 more estimates are for a 256-bit elliptic curve
built, in processors that run circuits (ink): 53 (2019), 127, 433, 1,180 (2023), 1,121, 105, 256, 98, 120;
an array of 6,100 atoms (2024) runs no circuits; a planned machine of 1,040 is left out
logical qubits: 1,200 to 4,000 needed; at most 70 demonstrated with error correction (2026)
your guess: a machine in 2035, 8.1 years from 30 November 2026; secret for 10 years + a migration
of 10 = 20 > 8.1: exposed for up to 11.9 years
(the live figure needs JavaScript and loads about 0.03 MB of data)
Qubits needed and qubits built, as published. Green: estimates of the machine that would run Shor's algorithm (dots: RSA-2048; squares: a 256-bit curve), filled for a surface code on a grid, outlined for other designs, each named with its run time. Hatched: enough by one named estimate, Gidney 2025. Ink: processors built and, below, logical qubits demonstrated. Counts alone mislead, since error rates, speeds and designs differ: point at a mark to read its assumptions. The upright line is your guess of the year a machine arrives; the sliders apply Mosca's inequality to it. No trend is fitted.

In estimates of one design, a surface code on a grid, the machine that factors a 2,048-bit modulus shrank from about a billion physical qubits in 2012 to 20 million in 2019 and to under a million in 2025: about 1,100 times fewer in 13 years.A. G. Fowler, M. Mariantoni, J. M. Martinis and A. N. Cleland, "Surface codes: Towards practical large-scale quantum computation", Physical Review A 86, 032324 (2012), arXiv 1208.0928: about a billion qubits and 26.7 hours, for a 2,000-bit number. C. Gidney and M. Ekerå, "How to factor 2048 bit RSA integers in 8 hours using 20 million noisy qubits", Quantum 5, 433 (2021), arXiv 1905.09749, posted in 2019. C. Gidney, "How to factor 2048 bit RSA integers with less than a million noisy qubits", arXiv 2505.15917 (2025): 897,864 qubits, 4.96 days, 1,537 logical qubits. The last two assume a gate error rate of 0.1% and an error-correction cycle of one microsecond. Part of that was bought with time, since the run grew from 8 hours to 4.96 days in the last step. The preprints of 2026 that go lower, to fewer than 100,000 qubits and then to between 11,000 and 23,000, change the design: other codes, qubits made of single atoms, qubits assumed to suffer only one of the two kinds of error. They describe hardware that no one has built.P. Webster and others, "The Pinnacle Architecture: Reducing the cost of breaking RSA-2048 to 100 000 physical qubits using quantum LDPC codes", arXiv 2602.11457 (February 2026): fewer than 100,000 qubits with quantum low-density parity-check (LDPC) codes, and a run of about a month. M. Cain and others, "Shor's algorithm is possible with as few as 10,000 reconfigurable atomic qubits", arXiv 2603.28627 (March 2026): 11,000 to 14,000 atoms for RSA-2048. A. Pappalardo and others, "Shor's algorithm compiled on cat qubits: 22 593 qubits for RSA-2048 in 3.14 days", arXiv 2610.37839 (October 2026). All three come from companies.

Against the estimates stand the machines. As of November 2026 the largest processors that run circuits have about a thousand physical qubits: 1,180 atoms announced by Atom Computing in October 2023, and 1,121 on IBM's chip of December 2023. The count is the smaller part of the gap. The estimates need error-corrected logical qubits by the thousand, between 1,200 and 4,000 of them, and the most demonstrated with error correction is 70, announced by IBM and the University of Chicago in July 2026. A count of qubits alone compares nothing, which is why every estimate on the chart carries its design and, where its paper states one, its run time: each is one point on a trade between qubits, hours and the error rate assumed.

None of these numbers put a calendar date on a capable machine, and the figure fits no trend line. The urgency to migrate key agreement now needs no forecast. Every classical key exchange transmits its public shares in the clear alongside the symmetrically encrypted session data, and a packet capture keeps indefinitely: whoever records today's sessions can run Shor's algorithm to recover the private exponent on the day a capable machine arrives.

Even though the transition to post-quantum cryptography is starting before a cryptanalytically relevant quantum computer has been built, there is a pressing threat. Encrypted data remains at risk because of the “harvest now, decrypt later” threat in which adversaries collect encrypted data now with the goal of decrypting it once quantum technology matures. Since sensitive data often retains its value for many years, starting the transition to post-quantum cryptography now is critical to preventing these future breaches. This threat model is one of the main reasons why the transition to post-quantum cryptography is urgent.

—NIST, Transition to Post-Quantum Cryptography Standards, IR 8547 (2026). Section 1, p. 1, of the final report of October 2026.

The arithmetic is known as Mosca's inequality: if data must stay secret for \(x\) years and the migration takes \(y\) years, while a machine arrives in \(z\) years, then \(x + y > z\) means that some of the data can be read while it must still be secret.NIST IR 8547, Section 3, p. 8, where it is called Mosca's theorem. Mosca's own guess, made in 2015, was an even chance that RSA-2048 would be broken by 2031: M. Mosca, "Cybersecurity in an era with quantum computers: will we be ready?", ePrint 2015/1075, abstract. The date in it is anybody's guess. The chart starts the reader's own at 2035, the year after which NIST's schedule of October 2026 disallows the algorithms of Section 1 (Section 11 has it): a place to begin, not a forecast.

That exposure explains why browsers migrated key agreement first, while authentication remains the open problem of Section 11. Signatures cannot be broken retroactively from old packet captures: a signature has to be forged while its public key is still trusted, after a quantum computer exists. NIST's report notes that signatures are immune to harvest-now-decrypt-later yet urgent all the same, because replacing certificate chains and hardware roots of trust takes years of coordination across many organizations. Replacing both key agreement and signatures requires mathematical problems in which nobody has found a hidden period for a quantum Fourier transform to see. Every mainstream public-key scheme since 1976 conceals one. Section 3 turns to the main replacement, lattices, where secrets hide behind high-dimensional geometry and small errors rather than periodic cycles, and Section 5.6 states one qualification, posted on 30 November 2026, for lattices with extra algebraic structure.

← Back to all posts