Algorithms

Shor's Algorithm

A quantum algorithm that factors large integers and finds discrete logarithms in polynomial time, threatening RSA and elliptic-curve cryptography.

Definition

Shor's algorithm is a quantum algorithm, published by Peter Shor in 1994, that factors an integer into its prime factors far faster than any known classical method. Because the security of RSA encryption rests on factoring being hard, a large enough quantum computer running Shor's algorithm could break it.

In depth

The best way to understand Shor's algorithm is through the small example N = 15. Choose a = 7. The sequence 7^x mod 15 runs 1, 7, 4, 13, 1, 7, 4, 13, and so on, so the period is r = 4. Since r is even, compute 7^(4/2) = 49, then gcd(49 − 1, 15) = gcd(48, 15) = 3 and gcd(49 + 1, 15) = gcd(50, 15) = 5. The factors are 3 and 5. The quantum computer's only job in this recipe is to find the period r; everything else is ordinary arithmetic that a laptop can do.

Finding the period is hard for a classical computer when N has hundreds of digits, because the sequence repeats only after a huge number of steps. The quantum algorithm prepares a superposition of all inputs x, computes a^x mod N into a second register, and then applies the quantum Fourier transform to the first register. Interference makes the measured value cluster around multiples of 2^n divided by r, from which a continued-fraction calculation recovers r. A run can fail, so the algorithm is repeated a few times.

The cost in qubits and gates is the real issue. A 2025 paper by Craig Gidney estimates that a 2048-bit RSA integer could be factored with fewer than a million noisy physical qubits in under a week, a large reduction from earlier estimates but still far beyond today's machines. Our lesson on Shor's algorithm and the post-quantum cryptography lesson work through these numbers.

Technical Definition

The algorithm reduces factoring N to finding the period r of the function f(x) = a^x mod N for a randomly chosen a. A quantum computer finds r using the quantum Fourier transform and phase estimation, and a classical step then computes gcd(a^(r/2) ± 1, N) to obtain a factor. The running time is polynomial in the number of bits of N, while the best known classical algorithms are super-polynomial.

Visual Explanation: An Analogy

Imagine a very long, repeating pattern that is too long to see in one glance. A classical computer must walk along it step by step to find how often it repeats. The quantum computer is like a prism that turns the whole pattern into a single bright spot whose position reveals the repeat length. Once you know the repeat length, a short calculation gives the factors.

Key facts

ItemDetail
PublishedPeter Shor, 1994
Problem solvedInteger factoring and discrete logarithms
Key subroutineQuantum Fourier transform for period finding
Small exampleN = 15, a = 7, period 4, factors 3 and 5

Where the idea comes from

Peter Shor presented the algorithm in 1994 while at Bell Labs. It transformed quantum computing from a curiosity into a topic of national security interest, because it showed that a practical problem with real economic importance had a fast quantum solution.

Real-World Use Cases

  • Breaking RSA and elliptic-curve public-key cryptography on a large fault-tolerant quantum computer
  • Motivating the move to post-quantum cryptography standards
  • Serving as the textbook example of a superpolynomial quantum speed-up

How it differs from related ideas

  • Shor's algorithm gives a superpolynomial speed-up for factoring, while Grover's algorithm gives only a quadratic one for unstructured search.
  • The best classical factoring methods take sub-exponential time, which is still impractical for 2048-bit numbers.

Common Misconceptions

  • Shor's algorithm does not break all encryption. Symmetric ciphers such as AES are affected far less, and post-quantum public-key schemes are designed to resist it.
  • No quantum computer today can factor a cryptographically relevant number. Demonstrations have factored very small numbers such as 15 and 21.

Frequently asked questions

Can a quantum computer break RSA today?

No. The machines that exist today have too few reliable qubits. Published estimates for RSA-2048 are on the order of a million noisy physical qubits.

Does Shor's algorithm break Bitcoin?

It threatens the elliptic-curve signatures used to authorise spending, but not the hashing used in mining. See our lesson on quantum computing and Bitcoin.

What replaces RSA?

Post-quantum algorithms such as the NIST standards ML-KEM and ML-DSA, which run on ordinary computers.

Related Terms

Learn it in a lesson

← Back to the dictionary