Skip to content
Tech Interview Prep
Technical interview guide

Quantum Algorithms II: Shor's Algorithm & Cryptographic Implications

How Shor's algorithm factors integers exponentially faster than any known classical method, and why that breaks RSA/ECC and drives the shift to post-quantum cryptography.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v3
Editorial status
Reviewed

Scope: IBM Quantum current Shor/QPE documentation; Shor primary paper; NIST FIPS 203/204/205, IR 8547 draft, SP 800-57, and crypto-agility guidance reviewed 2026-09-04.

Overview

Curated: · Written: · Reviewed:

Quantum Algorithms II: Shor's Algorithm & Cryptographic Implications

In one line

Shor's algorithm finds the period of a^x mod N on a fault-tolerant quantum computer, which breaks integer factorization and discrete log in polynomial time. Reach for it when asked which deployed primitives fall to a quantum adversary, and why.

Key definitions

  • Order r: the least positive integer with a^r ≡ 1 (mod N).
  • Abelian hidden subgroup problem: the problem class Shor solves. Factoring and discrete log are both instances.
  • Logical vs physical qubit: an error-corrected qubit vs a device qubit. Any estimate must quote both.
  • Continued fractions: the classical step that recovers a candidate r from the measured integer near s/r.
  • CRQC: cryptographically relevant quantum computer, the threshold the migration clock is measured against.

Formulas and complexity

ar≡1(modN)a^{r} \equiv 1 \pmod{N} gcd⁡(ar/2−1, N)andgcd⁡(ar/2+1, N)\gcd(a^{r/2}-1,\,N) \quad \text{and} \quad \gcd(a^{r/2}+1,\,N) Order finding: poly(log⁡N) gates. QFT: O(n2) gates for an n-bit modulus.\text{Order finding: } \mathrm{poly}(\log N) \text{ gates. QFT: } O(n^2) \text{ gates for an } n\text{-bit modulus.} Mosca: exposed if x+y>z\text{Mosca: exposed if } x + y > z

Where x is the confidentiality lifetime, y the migration time and z the years until a CRQC. A 25-year secrecy requirement plus a 7-year migration is exposed against any horizon under 32 years.

Classical comparison: the general number field sieve is heuristically L_N[1/3, 1.923]. The speedup is relative to the best known classical algorithm, not a proven lower bound.

How it works

Classical preprocessing: pick a with 1 < a < N. If gcd(a, N) ≠ 1, you already have a factor. Quantum step: phase estimation on multiplication by a mod N, then an inverse QFT, yields an integer close to s/r. Classical step: continued fractions give a candidate r, which you confirm by modular exponentiation. Factor extraction: if r is even and a^(r/2) ≢ ±1 (mod N), take gcd(a^(r/2) ∓ 1, N).

yes no yes no Pick base a gcd a N ≠ 1? Factor found classically Phase estimation and inverse QFT Continued fractions give candidate r r even and a^r/2 ≠ ±1? gcd gives factors, verify product

Worked trace, N = 15, a = 2: r = 4, a^2 = 4, gcd(3, 15) = 3, gcd(5, 15) = 5. Worked trace, N = 15, a = 14: r = 2, but a^1 ≡ -1, so both gcds are trivial. Discard the base.

When to use and when not to

PrimitiveUnderlying problemBroken by Shor?
RSA encryption and signaturesfactoringyes
ECDH (X25519), ECDSA (P-256), Ed25519discrete log in an elliptic curve groupyes
FFDH, DSA, ElGamaldiscrete log in a cyclic groupyes
AES-256-GCM, SHA-384, HMACunstructured searchno; Grover gives only a quadratic speedup
ML-KEM (FIPS 203), ML-DSA (FIPS 204), SLH-DSA (FIPS 205)lattice or hash-basednot affected by Shor

Traps interviewers probe

  • "Quantum breaks all encryption." Fix: name the assumption. Factoring and discrete log fall; symmetric primitives and hashes survive with parameter review.
  • "Factoring 21 means RSA-2048 is close." Fix: small demonstrations often compile away the modular arithmetic that dominates cost at 2048 bits. Ask which of logical qubits, non-Clifford gate count, code distance and success probability was measured.
  • "AES-128 is 64-bit after Grover." Fix: the arithmetic is right, but Grover's iterations are sequential, and parallelizing across k machines improves the count by only sqrt(k).
  • "Two algorithms means double security." Fix: hybrid safety depends on the combiner, negotiation, key derivation and failure semantics.
  • Accepting the first continued-fraction denominator. Fix: verify each candidate by modular exponentiation. For N = 15, a = 7, the fraction 2/3 gives candidate 3, but 7^3 mod 15 = 13, so reject it and test multiples.

Interview tips

Open with the assumption: "Shor solves period finding, which breaks factoring and discrete log, so RSA and elliptic-curve key exchange and signatures are broken, while AES-256 and SHA-384 survive."

Expected follow-ups: Why are ECC keys smaller but not safer against Shor? Why does RSA-8192 not help? Why does Grover not break AES-256? What is the logical-to-physical qubit ratio? What does Mosca's inequality say about your data?

30-second outline:

  1. Shor is period finding over an abelian group. Factoring and discrete log are instances.
  2. Order finding is quantum. Continued fractions and gcds are classical, and every candidate is verified.
  3. RSA, DH and ECC fall. AES-256 and SHA-384 remain, with Grover as a quadratic effect.
  4. Migration is sequenced by data lifetime: key exchange first, long-lived signatures next, symmetric parameters last.
  5. Name what is unknown: the CRQC arrival date, and the real physical qubit count.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.