Shor's Algorithm
Definition
Shor's algorithm, discovered by Peter Shor in 1994, is a quantum algorithm that factors integers in polynomial time — specifically gate operations for an -bit integer. This is exponentially faster than the best known classical algorithm (the general number field sieve, which runs in subexponential time ). Because RSA encryption derives its security from the hardness of integer factorisation, a large-scale quantum computer running Shor's algorithm would break RSA-2048 in hours — a task estimated to take trillions of years on classical hardware.
Algorithm Outline
Shor's algorithm reduces factorisation to the order-finding problem: given (the number to factor) and a random coprime to , find the smallest such that . Once is found, the factors are .
The algorithm proceeds in five steps:
Step 1: Classical Preprocessing
If is even, or if , the factors are trivial. Otherwise, choose a random such that .
Step 2: Quantum Order Finding
Prepare a quantum circuit with two registers:
- Register 1: qubits (where ), initialised to .
- Register 2: qubits, initialised to (or for the modular exponentiation).
The circuit performs:
Superposition: Apply Hadamard gates to all qubits in Register 1:
Modular exponentiation: Compute into Register 2:
Inverse quantum Fourier transform (QFT†): Apply the inverse QFT on Register 1, causing interference that peaks at values of that are multiples of .
Measurement: Measure Register 1. The outcome is (with high probability) close to for some integer .
Step 3: Classical Postprocessing
From the measured , use the continued fractions algorithm to extract (the order).
Step 4: Check the Result
If is even and , compute:
One of these is a non-trivial factor of .
Step 5: Retry if Necessary
The algorithm succeeds with probability (or with a few repeats). If it fails, choose a different and repeat.
Circuit Diagram (Simplified)
|0⟩ — H —●—————————————————————— QFT† — M —
|0⟩ — H —●—————————————————————— QFT† — M —
⋮ ⋮ ⋮
|0⟩ — H —●—————————————————————— QFT† — M —
│
|1⟩ ———╲_U╱———————————————————————————————
a^x mod N
Where is the unitary that computes .
Resource Estimates
| RSA key size | Logical qubits required | Physical qubits (assuming gate error) | Runtime estimate |
|---|---|---|---|
| 1024-bit | ~2,000 | ~1,200,000 | ~8 hours |
| 2048-bit | ~4,000 | ~3,500,000 | ~2 days |
| 4096-bit | ~8,000 | ~10,000,000 | ~2 weeks |
Estimates from Gidney & Ekerå (2021) using surface-code error correction and lattice-surgery operations.
Impact on Cryptography
Shor's algorithm breaks the following public-key cryptosystems:
| Cryptosystem | Problem solved by Shor | Current key size | Quantum resource (2048-bit equiv.) |
|---|---|---|---|
| RSA | Integer factorisation | 2048–4096 bits | ~4,000 logical qubits |
| ECDH (Elliptic Curve Diffie-Hellman) | Discrete logarithm | 256–521 bits | ~2,000 logical qubits |
| ECDSA | Discrete logarithm | 256–521 bits | ~2,000 logical qubits |
| DSA | Discrete logarithm | 2048 bits | ~2,500 logical qubits |
Countermeasure: Post-quantum cryptography (PQC) — NIST-standardised algorithms (ML-KEM, ML-DSA, SLH-DSA) are not vulnerable to Shor's algorithm because they are based on lattice problems and hash functions.
Variants and Generalisations
- Shor's algorithm for discrete logarithms: A direct adaptation solves the discrete logarithm problem in abelian groups (relevant for ECDH/ECDSA) using a nearly identical circuit structure.
- Hidden subgroup problem (HSP): Both Shor's and Grover's algorithms are special cases of the abelian hidden subgroup problem. Shor solves the cyclic group HSP; the discrete-log variant solves the product-of-cyclic-groups HSP.
- Variational factorialisation (VQF): A NISQ-era heuristic that uses a variational quantum eigensolver to factor small numbers (up to ~20 bits) but lacks Shor's provable exponential speedup.
Resources and References
- Shor, "Algorithms for quantum computation: Discrete logarithms and factoring" (1994), FOCS 1994, 124–134. [Original paper]
- Gidney & Ekerå, "How to factor 2048-bit RSA integers in 8 hours using 20 million noisy qubits" (2021), Quantum 5, 433. [Leading resource estimate]
- Quantum circuit implementations: qiskit.org/ecosystem/algos — Qiskit Algorithms includes modular exponentiation circuits.
- Beauregard, "Circuit for Shor's algorithm using 2n+3 qubits" (2002), arXiv:quant-ph/0205095. [Optimised qubit count]