How two people can agree on a secret key using nothing but entangled particles and the laws of quantum mechanics — explained, simulated, and visualized.
BBM92 is a quantum key distribution (QKD) protocol introduced in 1992 by Charles H. Bennett, Gilles Brassard, and N. David Mermin. It is an entanglement-based reformulation of the more famous BB84 protocol: instead of one party preparing and sending quantum states to the other, a source distributes pairs of entangled photons, one to each party, and the shared secret key emerges from the intrinsic randomness of their measurements.
Every BBM92 session moves key material through the same six stages:
A source generates pairs of photons in the entangled Bell singlet state:
|Ψ⁻⟩ = (|01⟩ − |10⟩) / √2
One photon of each pair goes to Alice, the other to Bob. Each of them independently and randomly chooses one of two measurement bases — rectilinear (Z) or diagonal (X) — and measures their photon. Because the pair is entangled, this isn't like flipping two independent coins: whenever Alice and Bob happen to choose the same basis, quantum mechanics guarantees their results are perfectly (anti-)correlated, no matter how far apart they are.
The chart below shows the actual basis choices from a real run of the simulation (first 80 of 300 entangled pairs). Hover over the points — this is a live, interactive Plotly chart, not a static image.
Over a public (but authenticated) classical channel, Alice and Bob reveal which basis they used for each trial — never their results. They keep only the trials where both chose the same basis and discard the rest. Since there are two bases, this keeps roughly 50% of the raw pairs.
Before trusting the sifted key, Alice and Bob sacrifice a random sample of it — publicly comparing the actual bit values (not just bases) — to estimate the Quantum Bit Error Rate (QBER). Any eavesdropping attempt on an entangled pair necessarily disturbs the correlation (a consequence of the no-cloning theorem and the monogamy of entanglement), which shows up as an elevated QBER. This simulation models an ideal, noiseless channel with no eavesdropper, so the estimated QBER should be essentially zero.
Any small residual mismatches in the sifted key are corrected via public error-reconciliation (a simplified, single-pass Cascade-style block-parity scheme in this implementation). Finally, privacy amplification compresses the reconciled key through a universal hash function — a random Toeplitz matrix in this case — so that any partial information an eavesdropper might have gathered is diluted to a negligible amount in the final key.
Once measured, each half of an entangled pair collapses into a definite state pointing along the axis it was measured in. The Bloch sphere below plots a small sample of Alice's and Bob's post-measurement qubit states from this run — points cluster on the poles of whichever axis (Z or X) each party happened to measure in.
| Protocol | Approach | Eavesdropper detection |
|---|---|---|
| BB84 | Prepare-and-measure, 4 states | Error rate vs. Alice's known preparation |
| E91 | Entanglement-based | Violation of Bell's inequality (CHSH) |
| BBM92 | Entanglement-based, 2 states | Correlation checks in complementary (Z/X) bases |
Because BBM92's key bits come from the inherent randomness of measuring an entangled state, no single party — not even the source — can predetermine the key. Combined with the fact that any interception attempt is physically detectable, this makes QKD resistant to "harvest now, decrypt later" attacks that threaten classical, computationally-secured key exchange in a post-quantum-computing world.
A QKD link only produces raw key material — a real deployment needs a Key Management System (KMS) to store, track, and dole out that key material to applications safely. The companion project behind this post implements exactly that:
ready → consumed / expired / revoked.The full source — the quantum simulation, the interactive dashboard, the KMS service, and the test suite — is open source. Clone it and run the whole pipeline locally:
# clone the project
git clone https://github.com/salavifa/bbm92-qkd
cd bbm92-qkd
# set up the environment
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
# terminal 1: start the Key Management System
uvicorn bbm92.kms.api:app --reload
# terminal 2: start the interactive visualization dashboard
python -m bbm92.visualization.dashboard.app
# then open http://127.0.0.1:8050
# or run the whole pipeline end-to-end from the CLI
python scripts/run_demo.py --num-pairs 1000 --seed 7
View the code on GitHub →