Curriculum / Entanglement & Protocols / BB84 Protocol Capstone

Lesson 9 of 11ProjectPro+250 XP

BB84 Protocol Capstone

Build a complete BB84 key distribution simulation.

BB84 Capstone

Time to build the whole thing. In the previous lesson you walked through BB84 on paper; in this project you implement every role in the protocol, Alice, Bob, and Eve, and watch the security argument come true in your own measurement statistics.

Your Project

The starter code gives you the protocol skeleton: random bit and basis generation, the per-qubit exchange loop, and the reporting. You implement the four pieces that matter, one per checkpoint.

Checkpoint 1, Alice encodes. Complete encode_qubit(bit, basis). Bit 1 means apply X; basis 1 (the X basis) means apply H afterward, turning |0⟩/|1⟩ into |+⟩/|−⟩. A built-in self-test checks all four encodings and prints the checkpoint marker.

Checkpoint 2, Bob measures. Complete measure_qubit(qc, basis). Bob cannot read the X basis directly: when his basis is 1 he must apply H before the Z measurement, rotating |+⟩/|−⟩ back to |0⟩/|1⟩. The self-test confirms that matching bases round-trip every bit perfectly.

Checkpoint 3, basis reconciliation. Complete sift(...): keep exactly the positions where Alice's and Bob's bases agree. On a quiet channel the sifted keys must match bit for bit, and about half the qubits survive.

Checkpoint 4, eavesdropper detection. Complete eve_intercept(qc): Eve measures the incoming qubit in a random basis of her own and resends what she found, the classic intercept-resend attack. Then run the protocol with Eve on the line. Theory says she corrupts 25% of the sifted key; the abort rule fires whenever the measured error rate (QBER) exceeds 11%.

What Success Looks Like

Run 1 (no Eve): sifted keys match, QBER 0%, a usable shared secret. Run 2 (Eve on every qubit): QBER lands near 25% and the program prints the abort. The protocol works not because Eve is clumsy, but because physics forces her to leave statistical fingerprints.

Block parse error

Invalid JSON in block:visualization: Unexpected non-whitespace character after JSON at position 852 (line 2 column 1)

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 multi-step project that combines several concepts into one larger build, checked checkpoint by checkpoint as you go.

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.