- Algorithms
- Also: Shor's factoring algorithm
Shor's Algorithm
A quantum algorithm that factors large integers exponentially faster than any known classical algorithm, threatening current RSA encryption.
Shor’s algorithm, developed by Peter Shor in 1994, is the single most consequential result in quantum computing. It factors large integers in polynomial time: quantum operations. The best known classical algorithms for factoring take sub-exponential time, growing faster than any polynomial. For RSA-2048, the best classical methods require more computational work than the age of the universe allows. Shor’s algorithm, on a sufficiently large fault-tolerant quantum computer, would do it in hours.
RSA, ECDSA, and Diffie-Hellman key exchange all derive their security from the hardness of factoring or the related discrete logarithm problem. Shor’s algorithm breaks all of them.
The details
The algorithm works by reducing factoring to period finding. Given a number to factor and a random integer (coprime to ), the function:
is periodic with some period . Once is found, it is often possible to compute factors of using classical number theory: if is even and , then gives a non-trivial factor of with high probability.
The quantum part finds efficiently using the Quantum Fourier Transform:
-
Prepare a superposition over all inputs:
-
Apply the function in superposition using a quantum oracle:
-
Measure the second register. This collapses the first register into a superposition of all values that produce the same , which are spaced apart.
-
Apply the QFT to the first register. The QFT converts the periodic pattern into peaks at multiples of in frequency space.
-
Measure the first register. The result is a multiple of ; classical continued fractions algorithms recover .
The circuit structure:
|0...0⟩ ──[H⊗n]──[U_f]──[QFT]──[M]──→ extract period r
|0...0⟩ ─────────[U_f]──────────[M]──→ (auxiliary register)
The QFT step is what provides the exponential speedup. The classical part (finding factors from the period) runs in polynomial time with no quantum resources.
Hardware requirements: Factoring RSA-2048 requires approximately logical qubits, implying roughly million physical qubits at current surface code overhead. Current largest processors have around physical qubits with no error correction.
Why it matters for learners
Shor’s algorithm is the primary motivation for the entire field of post-quantum cryptography. The threat it poses to RSA is why NIST spent eight years selecting and standardizing post-quantum algorithms. It is why intelligence agencies around the world are concerned about “harvest now, decrypt later” attacks.
Understanding Shor’s algorithm requires understanding superposition (to see why the quantum part works), the QFT (the engine of the speedup), and quantum circuits (to follow the circuit structure). It is an excellent capstone for a first quantum computing course.
The algorithm is also a clean example of how quantum speedup works: not by brute force, but by exploiting mathematical structure (periodicity) through a quantum transformation (QFT) that has no efficient classical equivalent.
Common misconceptions
Misconception 1: Shor’s algorithm currently threatens encryption. As of 2026, the largest integers factored by quantum hardware using Shor’s algorithm are in the range of 15 to 21. Factoring RSA-2048 requires millions of physical qubits with error correction. Current machines are several orders of magnitude away in both qubit count and quality.
Misconception 2: Shor’s algorithm can also break symmetric cryptography. Shor’s algorithm exploits specific number-theoretic structure (periodicity of modular exponentiation) that does not exist in symmetric encryption or hash functions. Grover’s algorithm provides a quadratic speedup on brute-force attacks, but this is addressed by doubling key lengths, not by replacing algorithms.
Misconception 3: The QFT is the hardest part to implement. The modular exponentiation step ( in the circuit) is actually far more expensive in terms of gate count and circuit depth than the QFT. The QFT circuit uses gates; the modular exponentiation requires gates. Resource estimates for running Shor’s algorithm are dominated by the arithmetic circuits, not the QFT.