Project 08 · Ladder 3 · Advanced
Shor's Algorithm: break RSA in miniature
How it works
- Powers of 7, mod 15, walk a cycle: 1, 7, 4, 13 and back to 1.
- The quantum part measures that cycle. The peaks land at quarters, so the period is 4.
- With the period, 15 splits into 3 × 5. That's RSA, broken in miniature.
Build the algorithm that started the race to replace the world's public-key encryption. Factor 15 with a quantum circuit you build gate by gate, rebuild Alice's private key from her public one, and read a message she never meant you to see.
- Level
- Advanced
- Hours
- 5 to 7
- Automated tests
- 26
- Ships to
- GitHub
What you build
Shor's Algorithm in Python and Qiskit
In 1994 Peter Shor showed that a quantum computer could factor big numbers in polynomial time, vastly faster than any known classical method. That one result is why NIST's draft transition plan marks RSA-2048 as deprecated after 2030 and disallowed after 2035. In May 2025 Craig Gidney estimated that breaking RSA-2048 would take fewer than a million noisy qubits running for under a week.
You build Shor's algorithm from the ground up: a toy RSA, the classical attack it has to beat, the quantum order-finding circuit (phase estimation, controlled modular multiplication and an inverse quantum Fourier transform you write yourself), continued fractions, and the gcd trick that turns a period into prime factors. Then you crack an intercepted message.
The quantum ideas inside
- Quantum phase estimation
- Inverse quantum Fourier transform
- Modular multiplication
- Continued fractions
- RSA
Warm up free: the Quantum Fourier transform and Phase estimation tutorials in Qiskit use the same ideas, in one script you can run tonight.
Real output · Project 08Qiskit Aer simulator
python quantum_shor.py --seed 7 --plot shor_results.png
Shor's algorithm in miniature: N = 15, base a = 7, 8 counting qubits + 4 work qubits
Step 1 · multiplier: a·y mod 15 is right for y = 1 to 14 for 7 of 7 bases
Step 2 · inverse QFT on 8 qubits matches Qiskit's QFTGate: yes
Step 3 · circuit: 12 qubits; multipliers a^(2^j) mod 15 = 7, 4, 1, 1, 1, 1, 1, 1
Step 4 · ran it 1024 times; the most common results:
m = 0 phase m/2^8 = 0.0000 260 shots
m = 192 phase m/2^8 = 0.7500 256 shots
m = 64 phase m/2^8 = 0.2500 255 shots
m = 128 phase m/2^8 = 0.5000 253 shots
(Step 5, continued fractions: Section 7 shows every line)
Step 6 · Shor's algorithm, one shot per attempt:
attempt 1: a = 7, m = 128, phase 1/2: no r from this phase, run again
attempt 2: a = 8, m = 0, phase 0: no r from this phase, run again
attempt 3: a = 2, m = 192, phase 3/4: r = 4, so 15 = 3 x 5
Step 7 · cracking Alice's intercepted message (public key n = 15, e = 3; 91 blocks):
phi = (3 - 1)(5 - 1) = 8, so the private key is d = 3
the message says: (no spoilers: you read it yourself in Section 7, Step 7)
Success per shot, every base (1024 shots each): right r / factors found
(seven lines, one per base: Section 8 shows them)
Chart saved to shor_results.png
By the end
What you walk away with
- a toy RSA (key generation, encryption, decryption) and two classical attacks on it, timed
- a quantum order-finding circuit for N = 15, built from your own modular multiplier and inverse QFT
- continued fractions that turn a measured phase into the period r, and the gcd step that turns r into factors
- the full Shor loop, with its failure cases handled properly, and a cracked message
shor_results.png: the phase histogram with its s/r peaks labelled, and the success rate for every base- 26 tests, then Shor's algorithm on 21 with a general multiplier you write in Section 11
- a public GitHub repo, a portfolio paragraph and a LinkedIn post
Where it sits
Ladder 3: Advanced
AdvancedLadder 3
Shor's Algorithm
Break RSA in miniature.
Quantum Teleportation
Teleport a qubit, then send two bits by moving one.
Quantum Error Correction
Take a 5% error rate below 1%.
Your first circuit is 10 minutes away
Stop watching quantum. Start shipping it.
$0 today. 7 days free, then $7.99 a week or $190 a year. Cancel any time.