Shor's Algorithm

Research
Introduced by
Peter Shor
Year
1994
Type
Quantum algorithm
Family
Number-theoretic Algorithm

What does it do?

Shor's Algorithm is a quantum algorithm that factors integers and computes discrete logarithms in time polynomial in the number of digits of the input, whereas the best known classical methods for these problems are subexponential. Peter Shor's 1994 result showed that a sufficiently large quantum computer could run it, which made it the standard reference for the threat quantum computers pose to RSA and other discrete-logarithm-based public-key systems.

The algorithm has not been run at cryptographically relevant sizes.

The intuition behind the method

Factoring can be reduced to finding the order r of a randomly chosen number a modulo N, meaning the smallest r with a^r ≡ 1 (mod N). Finding r is hard on a classical computer in general. The quantum part evaluates a^x mod N for many values of x at once through superposition, and the quantum Fourier transform then makes measurement outcomes concentrate on values that reveal the period. Classical number theory, including continued fractions, converts the measurement into r and, when r is suitable, into prime factors. The quantum step is what makes period finding fast; the rest of the procedure is classical.

History

Peter Shor published the algorithm in 1994 in the proceedings of the Foundations of Computer Science symposium, where the abstract describes the work as the first examples of quantum cryptanalysis. An expanded version was later published in the SIAM Review journal. Small experimental demonstrations have been reported, but these involve very small integers and remain far from cryptographically relevant sizes.

When to use it

Choose Shor's algorithm when the question concerns the hardness of integer factorization or discrete logarithms, for example when assessing how a given RSA modulus or discrete-logarithm key size would fare against a fault-tolerant quantum computer. It is the relevant reference for planning cryptographic migration. Do not treat it as a practical method for computing factorizations today: running it on moduli of realistic size, such as 2048-bit RSA, requires fault-tolerant hardware that does not yet exist. It offers no known advantage for problems without period structure, such as general NP-complete problems, for which classical methods remain the practical choice on current hardware.

Limitations and considerations

  • Requires fault-tolerant hardware: the modular exponentiation circuit is deep, and errors must be corrected for the result to be reliable, so the resource overhead is very large.
  • Experimental demonstrations so far have factored only very small integers, which do not transfer to cryptographic sizes.
  • The speedup is relative to the best known classical methods, which are subexponential; the algorithm does not establish that classical factoring is inherently polynomial-time.
  • The algorithm is randomised: a run can fail to yield a factor and must be repeated with a new base a.
  • Implementing modular exponentiation and the quantum Fourier transform with high fidelity is technically demanding and error-prone.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Runs in time polynomial in the number of digits of the integer, whereas the best known classical factoring methods are subexponential.
  • One period-finding procedure handles both integer factorization and discrete logarithms, so a single hardware capability threatens both factorization-based and discrete-logarithm-based public-key systems.
  • Only the period-finding step is quantum; the post-processing uses standard number theory (continued fractions and greatest common divisors), which makes each step checkable.
  • Its resource requirements give a concrete target for fault-tolerant hardware, which is why it is used to frame the cryptographic threat.

Applications

  • Assessing the vulnerability of RSA and discrete-logarithm-based public-key systems to a future fault-tolerant quantum computer.
  • Guiding the migration to post-quantum cryptography, since this threat is the motivation for that work.
  • Serving as a reference case for resource estimates of fault-tolerant quantum hardware.
  • Teaching how quantum period finding is combined with classical number theory to factor integers.
  • Studying quantum approaches to order finding, the subroutine that carries the quantum speedup.

How it works

How it works

1

Two quantum registers are prepared: the first is placed in an equal superposition over many input values x, and the second is set up to hold the modular exponentiation result. The number N to be factored and a randomly chosen base a are fixed classically beforehand.

2

The quantum Fourier transform acts on the first register and turns the periodic structure of the modular function into a pattern of amplitudes. For a register of n qubits it uses a number of gates that grows polynomially in n, whereas the classical fast Fourier transform on 2^n values takes time exponential in n.

3

Modular exponentiation computes a^x mod N for many values of x in superposition, and the transform then concentrates probability on measurement outcomes that encode the order r of a modulo N. The modular exponentiation circuit is deep, which makes this the component most exposed to noise and decoherence.

4

The measured outcome approximates a fraction s/r, and continued fractions recover r from it. If r is even and a^(r/2) is not congruent to -1 modulo N, greatest common divisors of a^(r/2) ± 1 with N give nontrivial factors. Otherwise the run fails and is repeated with a new base a, because the algorithm is randomised and of Las Vegas type.

Common pitfalls

  • Treating small-number experimental demonstrations as evidence of progress toward RSA-scale factoring; the gap lies largely in error-correction overhead, not only in the number of qubits.
  • Estimating resources from logical qubit counts alone, which understates the physical hardware needed once error correction is included.
  • Assuming all public-key cryptography is equally exposed. Shor's algorithm targets factorization and discrete logarithms; schemes built on other hard problems are not broken by it.
  • Overlooking the classical preprocessing failure cases: if the chosen base yields an odd order or a trivial greatest common divisor, the run produces no factors and must be repeated.

Frequently asked questions

How many qubits are needed to factor a 2048-bit RSA key?

The answer depends on the error-correction scheme and hardware assumptions, so no single figure applies. The requirement is very large in both logical and physical qubits, and error-correction overhead dominates the physical count. No current device is close to this scale.

How long would it take to run Shor's algorithm on an RSA-2048 key?

The answer depends on gate speeds, circuit depth and error-correction overhead, which vary with hardware assumptions, so no single runtime applies. The main obstacle is building a fault-tolerant machine of sufficient size, not the classical arithmetic.

What is the quantum Fourier transform and why is it essential?

The quantum Fourier transform is the quantum analogue of the discrete Fourier transform. It can be implemented with a number of gates that grows polynomially with the number of qubits, whereas the classical transform on the same number of values takes time exponential in the number of bits. It converts the periodic structure of modular exponentiation into patterns that measurement can reveal, which is how the order is found.

Can Shor's algorithm be used to attack my current encrypted data?

Not with current hardware. Experimental demonstrations so far have factored only very small integers, far below cryptographic sizes. The 'harvest now, decrypt later' concern is that encrypted data captured today could be decrypted once fault-tolerant quantum computers exist.

Is there a quantum algorithm for all NP-complete problems?

No. Shor's algorithm exploits the periodic structure of modular exponentiation, which factorization and discrete logarithms have. No general quantum algorithm is known that solves NP-complete problems in polynomial time. Grover's search gives only a quadratic speedup for unstructured search, which does not change this picture.

Related methods

Sources

  1. Shor, P. W. (1994). Algorithms for quantum computation: discrete logarithms and factoring. Proceedings of the 35th Annual Symposium on Foundations of Computer Science, 124–134.

    Open DOI reference
  2. Shor, P. W. (1997). Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM Review, 41, 303–332.

    Open DOI reference
  3. Ekert, A. K., Raussendorf, R. (2014). A short introduction to quantum computing. Reviews of Modern Physics, 74, 339–373.

    Open publication reference