Ndovu elephant mark ndovu

CONCEPT · SHOR’S ALGORITHM

Shor’s algorithm

Shor’s algorithm factors integers and computes discrete logarithms in polynomial time: factoring reduces to period finding, the quantum Fourier transform finds the period, and continued fractions turn the measured value into the factors of N.

Peter W. Shor, FOCS 1994factoring and discrete logarithms, polynomial timecontext: the quantum threat guide
01 · The frame

Shor’s algorithm (1994) factors integers and computes discrete logarithms in polynomial time on a quantum computer. Factoring splits a number into its prime building blocks (15 = 3 x 5); a discrete logarithm is the exponent x hidden in an equation like g^x = h mod p. Polynomial time means the work grows with the digit count of the input rather than exponentially with it.

Both problems reduce to one move, period finding, and a quantum computer finds periods that the best classical algorithms cannot. Deployed public-key cryptography sits on exactly these two problems: RSA on factoring, finite-field Diffie-Hellman and elliptic-curve cryptography on discrete logarithms. Symmetric cryptography survives; the quantum threat guide carries the full what-breaks picture.

02 · The mechanism

Factoring becomes period finding.

Pick a random g with 1 < g < N and write its powers mod N (mod is the remainder after dividing by N): g, g², g³, ... The remainders repeat, and the repeat length r is g’s order. When r is even and g^(r/2) does not leave remainder N − 1, two gcds (greatest common divisors, computable classically by the Euclidean algorithm) expose a factor of N:

gcd(g^(r/2) − 1, N) and gcd(g^(r/2) + 1, N).

For a random g the checks pass with probability at least 1 − 1/2^(k−1), where k is the number of distinct odd prime factors of N (Miller 1976; Shor 1996, section 5). A failed draw retries with a fresh g. Writing out powers to find r is infeasible at RSA size: the sequence can run nearly N steps before repeating, and closing exactly that gap is the quantum computer’s job.

The quantum primitives.

A quantum register can hold a superposition: many values at once, each carrying anamplitude, a number whose squared size is the probability that the value appears when the register is measured. Amplitudes have direction, so contributions to the same outcome can reinforce or cancel (interference). Measurement samples one value; the rest are gone. The algorithm is built so that the useful values are the ones whose amplitudes line up.

The quantum core of one run.

The machine puts a first register into a superposition over all exponents x = 0 ... q−1, where q is a power of two chosen between N² and 2N², and computes g^x mod N into a second register by repeated squaring. That step, modular exponentiation, is the bottleneck of the whole algorithm, and it runs on quantum registers because it is built reversible. The quantum Fourier transform(the quantum version of the classical tool for reading frequencies out of a repeated signal) then acts on the first register, and interference does the work: amplitudes near multiples of q/r reinforce each other and cancel everywhere else. Measuring the first register returns a value c that, with high probability, sits near a multiple of q/r.

Classical post-processing.

c/q approximates d/r (d is an unknown constant) within 1/(2q). With q above N² that fraction is unique, and the continued-fraction expansion of c/q, a short classical algorithm that reads the best rational approximations out of a number, recovers r. One run yields r with probability at least φ(r)/(3r), where φ(r) (Euler’s totient) counts the numbers below r sharing no factor with r; the bound shrinks only like 1/log log r, so repeating the run a modest number of times makes failure rare, and classical tricks that also try 2r, 3r, ... for each candidate cut the expected run count to a handful.

Shor’s algorithm as a pipeline: classical setup picks a random g; the quantum core prepares a superposition over x, computes g^x mod N by repeated squaring, applies the quantum Fourier transform, and measures c; classical post-processing reads the order r out of c/q by continued fractions and splits N with two gcdsCLASSICAL · SETUPafter Shor (1996), section 5pick a random g, 1 < g < NN is the number to factorQUANTUM · ONE RUNsuperpositionx = 0 to q−1modular exponentiationg^x mod N, repeated squaringQFTFourier transformmeasureoutcome cCLASSICAL · POST-PROCESSINGcontinued fractionsc/q ≈ d/r gives the order rgcd(g^(r/2) − 1, N), gcd(g^(r/2) + 1, N)a factor of N; retry with a fresh g on failureq is the power of two with N² ≤ q < 2N². One measurement per run; runs repeat until the checks pass.

One run’s numbers, small enough to check by hand. On RSA-size moduli the sequence can run nearly N steps before repeating; finding the repeat length without writing the sequence out is what the quantum core does.

StepN = 15, g = 7
Powers of g mod N7, 4, 13, 1, 7, 4, ... : the sequence repeats every r = 4 steps
Parity checksr = 4 is even; g^(r/2) = 7² = 4, and 4 ≠ 15 − 1, so the gcds may split N
First gcdgcd(7² − 1, 15) = gcd(48, 15) = 3
Second gcdgcd(7² + 1, 15) = gcd(50, 15) = 5
Factors15 = 3 x 5
03 · What it breaks, and what it does not

Every widely deployed public-key system sits on one of the two problems the algorithm solves. The same 1994 paper that factors integers computes discrete logarithms with the same period-finding core, so the two hard problems fall together.

SystemRests onShor’s algorithm
RSAfactoringfalls: polynomial-time factoring removes the key-length margin
Finite-field Diffie-Hellmandiscrete logarithm mod pfalls: the same period-finding core solves discrete logarithms
ECC (ECDSA, ECDH, Ed25519)elliptic-curve discrete logarithmfalls: same core, different group
AES, ChaCha20, SHA-2/3no factoring or discrete-log structureunaffected by Shor; Grover’s quadratic speedup is answered by longer keys

The speedup against symmetric cryptography is different in kind. Grover’s algorithm (1996) searches an unstructured space of N keys in about √N steps, so an n-bit key works at roughly 2^(n/2) strength; doubling the key length restores it, which is why AES-256 and SHA-384/512 remain the symmetric answer. The threat guide carries the full break/survive picture.

04 · What it means for key sizes

A polynomial-time factoring algorithm removes the margin that long RSA moduli buy. RSA-2048 and RSA-4096 sit in the same complexity class: the runtime still grows only polynomially with the digit count, so the larger modulus raises the work by a modest factor while the needed machine stays the same kind. There is no RSA key length that answers the algorithm.

The deployed answer is replacement, not enlargement: ML-KEM, ML-DSA, and SLH-DSA rest on lattice and hash problems rather than factoring or discrete logarithms. Their byte costs are the price, and the standards guide’s size section carries the numbers.

05 · Verify it yourself
ClaimPrimary sourceStatus
Factoring and discrete logarithms have polynomial-time randomized algorithms on a quantum computer (1994)Shor, FOCS 1994; SIAM J. Comput. 26, 1484 (1997); arXiv:quant-ph/9508027verified (abstract)
Factoring reduces to order finding: gcd(x^(r/2) - 1, n) yields a factor unless r is odd or x^(r/2) leaves remainder n-1; a random x works with probability at least 1 - 1/2^(k-1), k = distinct odd prime factorsShor 1996, section 5 (the reduction goes back to Miller 1976)verified (paper text)
One run: superposition over a, reversible modular exponentiation by repeated squaring, Fourier transform A_q, measurement; q is the power of two with N² ≤ q < 2N²Shor 1996, sections 3-5verified (paper text)
Measured c lands near a multiple of q/r; |c/q - d/r| ≤ 1/(2q); continued fractions recover d/r, unique once q > N²Shor 1996, section 5 (Figure 5.1 plots q = 256, r = 10)verified (paper text)
One run yields r with probability at least φ(r)/(3r) ≥ δ/log log r; repeating O(log log r) times gives high probabilityShor 1996, section 5verified (paper text)
Modular exponentiation is the algorithm’s bottleneck: O(l) squarings and multiplications mod n for an l-bit modulusShor 1996, section 3verified (paper text)
Grover’s algorithm searches N unstructured keys in O(√N) steps: quadratic, not exponentialGrover, STOC 1996; arXiv:quant-ph/9605043verified (abstract)
Worked example: powers of 7 mod 15 run 7, 4, 13, 1 (r = 4); gcd(48, 15) = 3; gcd(50, 15) = 5this page’s arithmetic, checkable by handchecked

Textbook depth: Nielsen & Chuang, Quantum Computation and Quantum Information, the order-finding and quantum Fourier transform chapters. A compact companion exposition without the kets: Scott Aaronson, “Shor, I’ll do it” (2007).

06 · Where it bites

The run count stays polynomial, so the reason no cryptographically relevant quantum computer exists yet is not the arithmetic but the machine. The factoring circuit is specified overlogical qubits, each one held accurate by error correction spread across many noisy physical qubits, and that overhead is the gap no lab has closed yet. The threat guide’s estimates carry the qubit counts and how widely they diverge by assumption.

The quantum threat guide turns this mechanism into the migration picture: which deployed systems it breaks, why recorded traffic is at risk before any such machine exists, and what the standards and deadlines answer.