Multiplying two large prime numbers takes a computer a fraction of a second. Recovering the two primes from their product is, for a classical computer, impractical once the numbers are large enough. Much of today’s public-key cryptography is built on that asymmetry, and Shor’s algorithm is the reason it would not hold against a large quantum computer.
What does Shor’s algorithm do?
Peter Shor published the algorithm in 1994, while working at Bell Labs. It solves two related problems: finding the prime factors of a large integer, and computing discrete logarithms. On a quantum computer the number of steps grows only polynomially with the size of the number, whereas the best known classical methods grow faster than any polynomial.
Three families of cryptography depend on these problems:
- RSA, which relies on factoring
- Diffie–Hellman key exchange, which relies on discrete logarithms
- elliptic-curve cryptography, which relies on discrete logarithms on elliptic curves
Shor’s algorithm was also the first clear case of a quantum algorithm offering a large speed-up on a problem people really cared about, and it did much to turn quantum computing into a serious research field.
How does Shor’s algorithm work?
The core idea is to turn factoring into a different problem: finding a period.
Call the number to be factored N, and pick a smaller number a that shares no factor with N. Now look at the sequence a, a², a³, … and reduce each term to its remainder after division by N. This sequence eventually repeats; the length of the repeating cycle is called the period. For N = 15 and a = 7, for example, the remainders run 7, 4, 13, 1 and then start again, so the period is 4. Number theory that was known long before quantum computing shows that once the period is known, the factors of N can usually be computed from it in a few easy classical steps. If a particular choice of a does not work, another is tried.
Finding the period is the hard part. For large N the cycle is astronomically long, and no efficient classical method for finding it is known. This is the step the quantum computer takes over:
- A register of qubits is put into a superposition of many exponents, and the function is computed on it with a quantum circuit.
- The quantum Fourier transform is applied. It makes the many computational paths interfere: outcomes compatible with the period reinforce each other and the rest cancel out.
- A measurement then returns a value from which the period can be worked out classically.
Think of a sound made of a repeating pattern: a spectrum analyser shows a sharp peak at the repetition frequency, even though no single sample reveals it. The quantum Fourier transform does something similar to the amplitudes of the register. The comparison is loose: a quantum computer never sees the whole spectrum, only one measurement outcome per run. The algorithm is designed so that useful outcomes are likely.
So the algorithm does not test every possible factor at the same time. The skill lies in arranging the interference so that the single measurement result carries information about the period.
What would it take to run it?
Far more than today’s hardware offers. The computation involves a very large number of gate operations, and each one has to be performed almost without error. Current qubits are too noisy for that, so the algorithm must run on logical qubits protected by quantum error correction, and each logical qubit is built from many physical ones.
Published estimates for breaking an RSA key of the size used today range from hundreds of thousands to millions of physical qubits, depending on the assumptions made about hardware and error correction. These estimates have fallen over the years as methods improved, but they remain well beyond existing machines. Experimental runs of Shor’s algorithm have so far factored only very small numbers such as 15 and 21. No cryptographically relevant key has been broken with Shor’s algorithm, and nobody can reliably state when that will become possible.
What follows from it?
The practical consequence is planned replacement, not panic. Because the threat is specific to factoring and discrete logarithms, the answer is to move to public-key algorithms built on other problems: post-quantum cryptography, for which NIST published its first standards in 2024.
Two things explain why organisations act before the machine exists. Replacing cryptography across products and infrastructure takes years. And encrypted data captured today can be stored and decrypted later, the harvest now, decrypt later risk, so the confidentiality of long-lived data depends on decisions made now.
Symmetric ciphers and hash functions are outside the reach of Shor’s algorithm. They face only the much weaker speed-up of Grover’s algorithm.
How Q&Co can help
Q&Co designs and implements quantum algorithms and develops post-quantum security solutions for industry. If you want to understand what Shor’s algorithm means for your own systems, or to plan the move to post-quantum cryptography, get in touch.