Curriculum / Entanglement & Protocols / BB84 Quantum Key Distribution
BB84 Quantum Key Distribution
Implement the BB84 quantum cryptography protocol.
BB84 Quantum Key Distribution
Secure Communication
BB84 (Bennett & Brassard, 1984) was the first quantum cryptography protocol. It uses quantum mechanics to generate a shared secret key that is provably secure: not just computationally hard to break, but mathematically impossible to crack without detection.
The problem it solves is older than quantum computing. A one-time pad gives perfect secrecy, but only if Alice and Bob already share a secret key as long as the message. Classical key exchange (RSA, Diffie-Hellman) fills that gap by leaning on computational hardness assumptions, assumptions Shor's algorithm demolishes. BB84 takes a different road entirely: its security rests on physics. An eavesdropper does not face a hard math problem, she faces the no-cloning theorem and measurement disturbance, and no amount of computing power, classical or quantum, buys her way around those.
The Two Bases
BB84 uses two measurement bases:
- •Z-basis (rectilinear): |0⟩ and |1⟩: the standard computational basis
- •X-basis (diagonal): |+⟩ = (|0⟩+|1⟩)/√2 and |−⟩ = (|0⟩−|1⟩)/√2
Alice encodes each bit in a randomly chosen basis. Bob measures each qubit in a randomly chosen basis.
| Alice bit | Alice basis | Qubit sent | Bob basis | Bob result | Match? |
|---|---|---|---|---|---|
| 0 | Z | |0⟩ | Z | 0 | Yes |
| 1 | Z | |1⟩ | X | 0 or 1 (random) | No |
| 0 | X | |+⟩ | X | 0 | Yes |
| 1 | X | |−⟩ | Z | 0 or 1 (random) | No |
When bases match, Bob always gets the same bit as Alice. When they don't match, Bob gets a random result: useless for key generation.
The Full Protocol
- 1.Alice randomly chooses bits and bases (Z or X for each qubit)
- 2.She encodes: Z-basis sends |0⟩ or |1⟩, X-basis sends |+⟩ or |−⟩
- 3.Bob randomly measures each qubit in Z or X basis
- 4.Alice and Bob publicly compare bases only (not bits)
- 5.They keep only the bits where their bases matched: the raw key
- 6.They sacrifice a small sample to check for eavesdropping errors
This is the opening of the lesson. The full walkthrough, the interactive circuit, and the graded challenge continue inside myqubit.
How this lesson works
A guided reading lesson with interactive knowledge checks. Concepts are explained step by step with circuit diagrams and runnable examples, and you confirm understanding before moving on.
Part of: Entanglement & Protocols
Master multi-qubit systems, quantum teleportation, and cryptographic protocols.
This lesson is part of Pro
Unlock Entanglement & Protocols and all 10 tracks with Pro: $12.99/month, $79/year, or $97 lifetime. Start with the free track first if you are new.