This is the algorithm that made quantum computing famous outside physics departments: a way to factor large numbers exponentially faster than any known classical method — fast enough to break the RSA encryption protecting most of the internet, if a large enough quantum computer ever runs it. Every piece you need is already built. This chapter is purely assembly.
The classical reduction: factoring becomes order-finding
Shor's real insight wasn't quantum at all — it was noticing that factoring N reduces to a different problem: pick some a coprime to N, and find its order r, the smallest positive integer with aʳ ≡ 1 (mod N). Once you have an even r, simple classical arithmetic (Euclid's gcd algorithm) almost always hands you a real factor of N:
gcd(a^(r/2) − 1, N) and gcd(a^(r/2) + 1, N)
The only quantum step in the entire algorithm is finding r quickly. That's it. Everything else — the reduction above, and the final gcd computation — runs on an ordinary classical computer.
IntermediateFinding the order, quantum-mechanically
Define the unitary U|x⟩ = |ax mod N⟩. Its eigenvalues are exactly e^(2πis/r) for integers s — which means Ch. 30's quantum phase estimation, applied to U, estimates s/r directly. A classical algorithm called continued fractions then recovers r from that fraction. This is the entire quantum contribution: QPE turns "find r by trial division" (exponentially slow) into "estimate a phase" (efficient).
Why this is exponentially faster than anything classical
The best known classical factoring algorithm (the general number field sieve) takes time that grows roughly exponentially in the number of digits of N. Shor's algorithm's quantum step — QPE on modular exponentiation — takes time that grows only polynomially. For small numbers like 15, this difference is invisible; a laptop factors 15 instantly either way. For numbers with hundreds of digits — exactly the size used in real RSA encryption — the classical approach becomes intractable while Shor's algorithm, run on a sufficiently large and reliable quantum computer, would not. That gap, not the specific number 15, is the actual reason this algorithm matters: it's the single clearest example known of a quantum algorithm solving a practically important problem exponentially faster than any classical alternative.
Building a quantum computer with enough reliable qubits to factor a cryptographically meaningful number remains a hard, unsolved engineering problem — which is exactly the kind of noise and error this book's Part II (density matrices, damping channels) and the broader field of quantum error correction exist to fight.
- TextbookNielsen & Chuang, §5.3The complete derivation, including the continued-fractions step this chapter only summarizes.
- PaperShor, "Polynomial-Time Algorithms for Prime Factorization..." (arXiv)The original 1995 paper.
- Videominutephysics — How Quantum Computers Break The InternetA fast, accessible overview of why this specific algorithm matters for cryptography.
End of Part V
Quantum parallelism, oracles, and phase kickback (Ch. 22–23) built the foundation; Deutsch, Deutsch–Jozsa, and Bernstein–Vazirani (Ch. 25–27) showed the pattern at its simplest; Grover (Ch. 28) showed a different kind of speedup entirely; the QFT and phase estimation (Ch. 29–30) built the machinery this chapter just spent its entire length putting to use. There's no algorithm left in this book bigger than the one you just finished.