Research Explained · Algorithms
Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer
Peter W. Shor
AT&T Bell Laboratories · 1997 (conference version 1994) · Difficulty ★★★★☆
Reference
Shor, P. W. (1997). Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM Journal on Computing, 26(5), 1484-1509. arXiv:quant-ph/9508027. Conference version: Proceedings of the 35th Annual Symposium on Foundations of Computer Science (1994), 124-134.
Preprint: arXiv:quant-ph/9508027
This page is an independent explanation. For exact wording, figures, and data, read the original paper.
The short version
Peter Shor shows that a quantum computer could factor large numbers and compute discrete logarithms in polynomial time, problems whose difficulty protects most of today's public-key cryptography. The result turned quantum computing from a curiosity into a matter of national security.
Key findings
- Integer factoring can be done on a quantum computer in a number of steps that grows polynomially with the number of digits.
- The same method computes discrete logarithms, which breaks Diffie-Hellman and elliptic-curve cryptography as well as RSA.
- The key quantum step is finding the period of a function, using the quantum Fourier transform to make the period visible through interference.
- The algorithm is probabilistic and succeeds with high probability after a few repetitions.
Background: why this paper was written
In 1994 public-key cryptography rested on a handful of computational problems believed to be hard. RSA, invented in 1977, depends on the difficulty of factoring the product of two large primes, and the Diffie-Hellman and ElGamal systems depend on the difficulty of discrete logarithms. The best known classical factoring algorithms, such as the number field sieve, run in sub-exponential time, which is fast enough to defeat short keys and too slow for keys of a few thousand bits.
Quantum computing was then a small field. Deutsch had defined the quantum computer in 1985, and Deutsch and Jozsa in 1992, Bernstein and Vazirani in 1993, and especially Daniel Simon in 1994 had found problems where quantum computers beat classical ones in an artificial oracle setting. Simon's algorithm, which finds a hidden period of a function using a Fourier transform over bit strings, was the direct inspiration for Shor's work.
What the researchers did
Shor starts with a classical reduction. To factor N, pick a random number a that shares no factor with N and look at the order r, the smallest positive integer with a to the power r equal to 1 modulo N. If r is even and a to the r over 2 is not minus 1 modulo N, then the greatest common divisor of N with a to the r over 2 plus or minus 1 gives a nontrivial factor. This works for a random a with probability at least one half, so a few attempts suffice. The hard part for a classical computer is finding r.
The quantum part finds r. The algorithm prepares a register in an equal superposition of the integers from 0 to Q minus 1, where Q is a power of two larger than N squared. It computes a to the x modulo N into a second register, then measures the second register, which leaves the first in a superposition of values of x that are spaced r apart. Applying the quantum Fourier transform to the first register produces a state whose probability is concentrated near multiples of Q over r. Measuring gives a number close to such a multiple, and the continued fractions algorithm recovers r from it with good probability.
The paper gives the circuit for the quantum Fourier transform over the integers modulo 2 to the n, building on Coppersmith's 1994 work, and shows that modular exponentiation can be done with a polynomial number of gates by repeated squaring. It then adapts the same method to the discrete logarithm problem, using a two-dimensional version of the Fourier transform. The total running time is polynomial in the number of bits of N, roughly cubic in the simplest implementation.
Results
Factoring and discrete logarithms are in BQP, the class of problems solvable with bounded error in polynomial time on a quantum computer. Since the best known classical algorithms are sub-exponential, this is a super-polynomial speedup.
The paper implies that RSA, Diffie-Hellman, DSA, and elliptic-curve cryptography are all insecure against a large enough quantum computer. Symmetric ciphers and hash functions are not broken, since Grover's 1996 algorithm gives only a quadratic speedup against them.
Subsequent work refined the cost. Gidney and Ekerå estimated in 2019 that RSA-2048 could be factored in about eight hours with 20 million noisy qubits, and Gidney reduced this in 2025 to under one million noisy qubits running for less than a week, under stated assumptions about error rates and cycle time.
Key facts and numbers
| Item | Detail |
|---|---|
| Year | 1994 conference version; 1997 journal version |
| Running time | Polynomial in the number of bits; roughly O(n cubed) gates in the basic form |
| Best classical | Number field sieve, sub-exponential time |
| RSA-2048 estimate (2019) | About 20 million noisy qubits for 8 hours (Gidney and Ekerå) |
| RSA-2048 estimate (2025) | Fewer than 1 million noisy qubits for under a week (Gidney) |
Limitations and caveats
Running the algorithm on cryptographically relevant numbers needs fault-tolerant hardware with thousands of logical qubits, which does not exist. Small demonstrations, such as factoring 15 or 21, used shortcuts and do not indicate scalable capability.
The algorithm is specific to problems with a hidden periodic structure and does not speed up most other problems.
The classical reduction and the classical post-processing are part of the algorithm, and only the order-finding step is quantum.
Why it matters
Shor's algorithm is the reason governments and companies are migrating to post-quantum cryptography. NIST published its first post-quantum standards in 2024, and resource estimates for running the algorithm against RSA-2048 drive hardware roadmaps.
What happened next
The paper changed the status of quantum computing and began the work on error correction. Shor himself proposed the first quantum error-correcting code in 1995, partly to answer the objection that decoherence would make machines like this impossible.
It is the main driver of post-quantum cryptography. The harvest-now-decrypt-later concern, in which adversaries store encrypted data until quantum computers can read it, follows directly, and government timelines for migration run to the early and mid 2030s.
How to read the original paper
The first sections, which give the overview and the classical reduction, are readable with basic number theory. The sections on the quantum Fourier transform and the analysis of the measurement probabilities are technical.
For an easier route, read the Shor's algorithm and quantum Fourier transform pages on this site first, and then return to the paper.
Original abstract (paraphrased)
A computer is generally considered to be a universal computational device. The paper shows that on a quantum computer, the problems of finding the prime factors of an integer and of finding discrete logarithms can be solved in polynomial time with bounded error. It describes the order-finding subroutine using modular exponentiation and the quantum Fourier transform, and the classical reduction from factoring to order finding.
Frequently asked questions
Can Shor's algorithm break RSA today?
No. It needs a fault-tolerant quantum computer with thousands of logical qubits, and today's machines are far from that.
What did Shor actually prove?
That factoring and discrete logarithms can be solved in polynomial time with bounded error on a quantum computer.
Does it threaten all encryption?
No. It breaks public-key systems based on factoring and discrete logarithms, while symmetric ciphers such as AES-256 and hash functions remain secure.
Keep exploring
- Algorithm: Shor's Algorithm
- Algorithm: Quantum Fourier Transform (QFT)
- Algorithm: Simon's Algorithm
- Hardware: Google Willow
- Dictionary: Post-Quantum Cryptography
- Dictionary: Harvest Now, Decrypt Later
- Dictionary: BQP Complexity Class
- Dictionary: Quantum Speedup
- Industry: Quantum Computing for Cybersecurity
- Industry: Quantum Computing for Finance
- Industry: Quantum Computing and the Public Sector
Explanations on this page summarize published work for education (last reviewed September 30, 2026). Numbers are taken from the cited paper or from widely reported follow-up work, and later results may have updated or challenged them. Check the reference above before citing.