Shor's algorithm is a quantum factoring algorithm that decomposes large integers into prime factors in polynomial time, a computational feat that classical computers cannot achieve at cryptographically relevant key sizes.
Grover's algorithm solves a different problem entirely: unstructured database search. Where Shor's factoring algorithm dismantles the number-theoretic foundations of public-key cryptography, Grover's algorithm delivers a quadratic speedup over any classical linear search, pressing on symmetric ciphers and hash functions instead. Together these two algorithms define the quantum threat surface that post-quantum cryptography (PQC) standardization was built to address.
What Quantum Algorithms Actually Do
Shor's algorithm and Grover's algorithm solve fundamentally different problems using quantum mechanical principles that have no classical analog. Both require a fault-tolerant quantum computer, not the Noisy Intermediate-Scale Quantum (NISQ) devices available today. The quantum computing qubits and entanglement explainer covers the physical qubit requirements and decoherence constraints that separate NISQ hardware from fault-tolerant systems.
- Quantum superposition
- A qubit exists in a linear combination of |0'' and |1'' until measured. An n-qubit register encodes 2n states simultaneously, letting quantum circuits evaluate exponentially many inputs in a single pass.
- Quantum interference
- Algorithm design causes amplitude paths leading to wrong answers to cancel (destructive interference) while paths to correct answers reinforce (constructive interference). Both Shor's algorithm and Grover's algorithm depend on interference to extract a useful result from superposition.
- BQP complexity class
- BQP (Bounded-error Quantum Polynomial time) contains problems a quantum computer can solve in polynomial time with error probability below one-third. Integer factorization sits in BQP. Classical computing has no known polynomial-time factoring algorithm, which is why RSA depends on that hardness. Grover's quadratic speedup does not place unstructured search in BQP; it reduces the constant but leaves the search problem in a sub-polynomial regime relative to the key-space size.
- Oracle model
- An oracle is a black-box function that marks a target state by flipping its phase. Grover's algorithm is defined in the oracle model: apply the oracle, then the diffusion operator, and repeat. Shor's algorithm uses a different structure, reducing factoring to an order-finding problem solved via quantum period finding rather than oracle queries.
How Shor's Algorithm Factors Large Integers

Shor's algorithm reduces integer factorization to an order-finding problem, then uses quantum period finding and the quantum Fourier transform to solve that problem in polynomial time. Peter Shor showed that a quantum computer can factor an n-bit integer in a number of steps polynomial in the input size, as stated in the original paper (arXiv:quant-ph/9508027). RSA-2048 derives its security from the classical hardness of factoring 2048-bit semiprimes; a fault-tolerant quantum computer running Shor's algorithm erases that security at polynomial cost. The classical vs quantum computing comparison frames the gate-complexity gap between current hardware and the fault-tolerant systems this algorithm requires.
- Classical reduction to order-finding. Choose a random integer a coprime to target N. The goal becomes finding the order r of a modulo N, the smallest r such that ar ≡ 1 (mod N). Once r is known, gcd(ar/2 ± 1, N) yields the factors of N with high probability.
- Quantum period finding via quantum phase estimation. Prepare a superposition over all exponents, then apply modular exponentiation as a quantum gate. Quantum phase estimation (QPE) extracts the eigenphase of the resulting unitary, which encodes the period r. This is the step with no efficient classical analog: classical enumeration of a 2048-bit exponent space is intractable.
- Quantum Fourier transform output. The quantum Fourier transform (QFT) implements QPE by mapping periodic amplitude structure into sharp frequency-domain peaks. After measurement, the output is a rational number close to k/r for integer k.
- Continued-fraction recovery of r. Apply the classical continued-fractions algorithm to the measured value. This recovers r, which yields the prime factors of N. A small number of repetitions boosts success probability to near-certainty.
The polynomial time scaling means doubling an RSA key length adds only polynomial cost to Shor's runtime, not exponential cost as it does for classical factoring. RSA-2048 and elliptic-curve cryptography at equivalent security levels offer no asymptotic refuge against Shor's factoring algorithm on a fault-tolerant quantum computer.
How Grover's Algorithm Searches an Unsorted Database
Grover's algorithm uses oracle amplitude amplification to locate a target item in an unsorted set of N entries in O(sqrt(N)) operations, a quadratic speedup over the O(N) required classically. Lov Grover published this result in 1996 (arXiv:quant-ph/9605043). The quadratic speedup is provably optimal: Bennett, Bernstein, Brassard, and Vazirani demonstrated in 1997 that no quantum algorithm can solve an unstructured search problem in fewer than O(sqrt(N)) oracle queries, establishing the BBBV lower bound (arXiv:quant-ph/9701001).
- Initialize uniform superposition. Apply a Hadamard transform to all n qubits, placing the register in an equal-amplitude superposition over all N = 2n states. Each state starts with amplitude 1/sqrt(N).
- Apply oracle phase flip. The oracle marks the target state by flipping its amplitude sign from positive to negative. All other states are unchanged. The target amplitude is now slightly different from the rest.
- Apply diffusion operator. The Grover diffusion operator reflects all amplitudes about their mean. Because the target amplitude is negative, it rises after reflection; non-target amplitudes decrease slightly. Each cycle of oracle amplitude amplification followed by diffusion concentrates probability on the target.
- Repeat approximately pi/4 × sqrt(N) times. After this many Grover iterations the target-state amplitude approaches 1. Iterating beyond this point overshoots and reduces success probability.
- Measure. A single measurement returns the target state with probability near 1. Total oracle query count: O(sqrt(N)).
The cryptographic consequence is key-strength halving. Against AES-128, the search space is 2128 keys; Grover's algorithm reduces the effective work to 264 operations, dropping effective security to roughly 64 bits. AES-256 drops to roughly 128-bit effective security. NIST's analysis of Shor and Grover threat models, including the key-doubling mitigation for symmetric ciphers, is documented at the NIST IR 8105 page (csrc.nist.gov/pubs/ir/8105/final). The practical implication: doubling symmetric key length fully offsets Grover's quadratic speedup, whereas no key-length fix can neutralize Shor's exponential advantage against RSA or ECC.
Side-by-Side Comparison: Complexity, Target, and Threat Level
Shor's algorithm targets public-key cryptosystems with an exponential advantage over classical factoring; Grover's algorithm targets symmetric and hash-based schemes with a quadratic advantage that mitigation can offset by key-length doubling. The threat profiles are asymmetric: Shor's factoring algorithm completely breaks RSA-2048 and elliptic-curve cryptography at current key sizes, while Grover's algorithm weakens but does not break AES-256 or SHA-3. That asymmetry structures the entire NIST PQC response.
| Attribute | Shor's Algorithm | Grover's Algorithm |
|---|---|---|
| Problem class | Integer factorization; discrete logarithm | Unstructured database search |
| Classical complexity | Sub-exponential (general number field sieve) | O(N) linear scan |
| Quantum complexity | Polynomial time (BQP) | O(sqrt(N)) quadratic speedup |
| Primary cryptographic target | RSA-2048, elliptic-curve cryptography, Diffie-Hellman | AES-128, AES-256, SHA-2, SHA-3 |
| Cryptographic threat severity | Complete break at current key sizes | Effective key length halved; 256-bit keys remain adequate |
| Mitigation strategy | Replace with lattice-based cryptography or hash-based schemes | Double key length; AES-256 and SHA-3 are sufficient |
| NIST PQC response | FIPS 203 (ML-KEM), FIPS 204 (ML-DSA), FIPS 205 (SLH-DSA) | Retain AES-256 and SHA-3; no new standard required |
The threat-level asymmetry matters for migration planning. RSA-2048 and ECC offer zero residual security against a cryptographically capable fault-tolerant quantum computer running Shor's algorithm. AES-256 and SHA-3 retain 128-bit effective security under Grover's quadratic speedup, a level NIST accepts as post-quantum adequate.
Post-Quantum Cryptography: The NIST Response
NIST finalized three post-quantum cryptographic standards in August 2024 to replace algorithms vulnerable to Shor's algorithm: FIPS 203 (ML-KEM, lattice-based key encapsulation), FIPS 204 (ML-DSA, lattice-based digital signatures), and FIPS 205 (SLH-DSA, hash-based signatures). All three are part of the NIST post-quantum cryptography standardization project (csrc.nist.gov PQC project). The IBM vs Google quantum supremacy comparison covers the hardware milestones that frame when fault-tolerant quantum computing might become a practical threat.
- FIPS 203: ML-KEM (Module-Lattice-Based Key-Encapsulation Mechanism)
- Replaces RSA and elliptic-curve key exchange. Security rests on the Module Learning With Errors (MLWE) lattice problem, which has no known polynomial-time quantum algorithm. Addresses the Shor threat to key encapsulation directly. Published August 13, 2024 (FIPS 203).
- FIPS 204: ML-DSA (Module-Lattice-Based Digital Signature Algorithm)
- Replaces RSA-based and ECDSA digital signatures. Lattice-based cryptography construction provides resilience against Shor's algorithm on the signature verification path. Published August 13, 2024 (FIPS 204).
- FIPS 205: SLH-DSA (Stateless Hash-Based Digital Signature Algorithm)
- A hash-based signature scheme whose security rests solely on hash-function collision and preimage resistance. Addresses the Shor threat for signatures and is Grover-aware: SHA-3 with 256-bit output retains adequate post-quantum collision resistance after the quadratic speedup. Published August 13, 2024 (FIPS 205).
- Symmetric and hash guidance for Grover resistance
- AES-256 and SHA-3 with 256-bit or larger output require no algorithmic replacement. NIST guidance positions them as Grover-resistant at current key and output sizes. The key-doubling principle: a Grover attacker needs 2128 oracle queries against AES-256, which remains computationally infeasible.
NISQ-Era Constraints: Why Neither Algorithm Runs Today
Neither Shor's algorithm nor Grover's algorithm can execute at cryptographically relevant scale on any existing quantum processor because both require fault-tolerant quantum error correction (QEC) that current Noisy Intermediate-Scale Quantum hardware cannot provide. Quantum error correction encodes one logical qubit across many physical qubits and uses syndrome measurements to detect and correct errors without collapsing the encoded state. The gap between NISQ devices and a fault-tolerant quantum computer is architectural, not incremental.
- Gate fidelity. NISQ processors accumulate errors on every gate operation. Shor's algorithm requires circuits many layers deep at the logical qubit level. Without QEC, gate errors compound across circuit depth and corrupt the output before the period can be extracted.
- Decoherence time. Qubits lose their quantum state through environmental noise. A fault-tolerant quantum computer must complete QEC cycles faster than the physical qubit decoherence time, requiring cryogenic hardware with precision control electronics far beyond what current NISQ systems achieve.
- Logical qubit overhead. Surface code QEC, the leading candidate for near-term fault-tolerant quantum computers, requires hundreds to thousands of physical qubits per logical qubit at current error rates. Running Shor's algorithm at RSA-2048 scale requires thousands of logical qubits, placing the physical qubit count far beyond current fabrication.
- QEC overhead scaling. Reaching the logical error rates needed for a Shor-depth circuit pushes physical overhead to levels no current process can meet. The physical qubit requirement scales with the inverse of the physical error rate, and current error rates leave the required hardware count in the millions.
The practical upshot: the quantum threat to RSA-2048 and elliptic-curve cryptography is real but not imminent on NISQ hardware. The migration window exists today precisely because replacing deployed public-key infrastructure takes years, not because a quantum adversary is operational.
References
- Shor, Peter W. (1995). Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer. arXiv:quant-ph/9508027.
- Grover, Lov K. (1996). A fast quantum mechanical algorithm for database search. arXiv:quant-ph/9605043.
- Bennett, Bernstein, Brassard, Vazirani (1997). Strengths and Weaknesses of Quantum Computing. arXiv:quant-ph/9701001.
- NIST. FIPS 203: Module-Lattice-Based Key-Encapsulation Mechanism Standard.
- NIST. FIPS 204: Module-Lattice-Based Digital Signature Standard.
- NIST. FIPS 205: Stateless Hash-Based Digital Signature Standard.
- NIST. NIST IR 8105: Report on Post-Quantum Cryptography.
- NIST. Post-Quantum Cryptography Standardization Project.
Further reading
Frequently Asked Questions
What is Shor's algorithm used for in cryptography?
Shor's algorithm factors large integers in polynomial time on a fault-tolerant quantum computer, directly threatening RSA, DSA, and elliptic-curve cryptography. NIST finalized three post-quantum cryptographic standards (FIPS 203, 204, 205) in August 2024 precisely because a sufficiently powerful quantum computer running Shor's algorithm could break RSA-2048 in hours rather than the billions of years required classically.
Does Grover's algorithm break symmetric encryption?
Grover's algorithm does not break symmetric encryption outright; it halves effective key strength. AES-128 drops to roughly 64-bit security and AES-256 drops to 128-bit security against a quantum adversary. Because doubling key length fully offsets Grover's quadratic speedup, AES-256 and SHA-3 remain adequate under NIST post-quantum guidance.
Is Grover's quadratic speedup provably optimal for unstructured quantum search?
Yes. Bennett, Bernstein, Brassard, and Vazirani proved in 1997 that no quantum algorithm can solve an unstructured search problem in fewer than O(sqrt(N)) oracle queries, confirming Grover's algorithm is optimal. The lower-bound proof is available at arXiv:quant-ph/9701001.









