Project 07 · Ladder 2 · Intermediate
BB84 Quantum Key Distribution: catch a spy with the laws of physics
How it works
- Alice sends photons in random bases. Bob keeps the bits where their bases match.
- The kept bits (cyan) become a secret key that only the two of them share.
- Now Eve listens in. Measuring a photon disturbs it, so errors appear (red).
- Too many errors: Alice and Bob know someone listened, and throw the key away.
Catch a spy with the laws of physics. Build BB84, the protocol behind the 2025 Turing Award, send an eavesdropper in to listen, and watch the error rate jump to about 25% the moment she does.
- Level
- Intermediate
- Hours
- 5 to 7
- Automated tests
- 19
- Ships to
- GitHub
What you build
BB84 Key Distribution in Python and Qiskit
In 1984 Charles Bennett and Gilles Brassard asked a wild question: what if a secret key were protected by physics, instead of by maths that's hard to undo? Their answer, BB84, turns a law of nature into a burglar alarm. Measuring a qubit the wrong way scrambles it, so a spy can't read the key without leaving errors behind. In March 2026 that idea won Bennett and Brassard the 2025 ACM A.M. Turing Award, and versions of their protocol already run in real networks, over fibre and through satellites.
You build the whole protocol in Qiskit: Alice's random bits and bases, Bob's random measurements, the public sifting conversation, a spy called Eve running an intercept-resend attack, and the error check that exposes her. Then you learn exactly what the guarantee rests on, which is what makes you credible in a quantum security interview.
The quantum ideas inside
- Quantum key distribution
- Measurement bases
- No-cloning
- Quantum bit error rate
- Intercept-resend attacks
New to Qiskit? Run your first circuit free, or warm up with the free Qiskit tutorials.
Real output · Project 07Qiskit Aer simulator
python quantum_bb84.py --bits 2000 --eve --seed 7 --plot bb84_results.png
First 12 qubits (basis Z/X):
Alice sends : |-> |0> |1> |0> |+> |0> |1> |0> |0> |+> |0> |1>
Bob's basis : Z Z X X Z Z X Z Z Z X Z
Bob measures: 1 0 0 1 1 0 0 0 1 0 0 0
Kept? : - Y - - - Y - Y Y - - Y
With Eve : raw=2000 sifted=1027 sampled=256 QBER(sample)=0.301 -> ABORT final key=0 bits
Eve's measurements match Alice on 75.9% of the sifted bits she intercepted
Classical wire with Eve: error rate 0.000, Eve's copy correct: True (undetectable)
Chart saved to bb84_results.png
By the end
What you walk away with
- Qiskit circuits that prepare and measure the four BB84 states
- sifting, an error-rate check (the QBER) and an abort rule
- an intercept-resend spy who can intercept any fraction of the qubits, plus optional channel noise
- a classical comparison where the eavesdropper copies everything and is never noticed
bb84_results.png: the error rate per scenario, and as Eve gets greedier- 19 automated tests, plus 6 bonus tests with exact answers
- one extension that is yours alone
- a public GitHub repo, a portfolio paragraph and a LinkedIn post
Where it sits
Ladder 2: Intermediate
IntermediateLadder 2
Grover's Search
Find one name in 16 in 3 looks.
Quantum Maze Solver
An oracle that never sees the answer.
BB84 Key Distribution
Catch a spy on the line. Its inventors won the 2025 Turing Award.
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.