Alice sends a stream of photons, each polarized to encode one random bit in one of two randomly chosen bases: rectilinear (+) β 0Β°/90Β° β or diagonal (Γ) β 45Β°/135Β°. Bob measures each photon in his own randomly chosen basis, with no way to know Alice's choice in advance.
Afterwards, Alice and Bob publicly compare (not their bits, only) their bases for each photon and keep only the bits where both happened to choose the same basis β the sifted key. On average this discards half the photons.
If an eavesdropper Eve intercepts a photon, she must also guess a basis to measure it β and quantum mechanics forbids her from copying the unknown state (no-cloning theorem). When her guess is wrong she collapses and resends the wrong state, which flips roughly a quarter of Bob's sifted bits relative to Alice's. Alice and Bob sacrifice a public sample of the sifted key to measure this quantum bit error rate (QBER): near 0% means the channel is secure, ~25% reveals an eavesdropper.
- Turn Basis randomization off to see the insecure case: if Alice and Bob always use the same fixed basis, Eve can match it too and intercept the entire key with zero detectable error β the QBER stays at 0% even though the channel is fully compromised. This is why true randomness in basis choice is essential, not just a convenience.
- Turn Eavesdropper on with randomization on to watch the QBER climb toward ~25% and trigger detection once enough sifted bits have been sampled.