BB84 Key Sifting Statistics: Measured QBER vs the 25% Intercept-Resend Limit

Send photons through BB84 with an optional intercept-resend eavesdropper and compare the measured error rate with theory.

Check running...
The science

Alice picks a random bit a and a random basis (+ rectilinear or × diagonal) for each photon; Bob picks his own random basis. If the bases agree Bob reads a with certainty; if not, his outcome is a fair coin. Bob and Alice then publicly compare bases and keep only matching positions (the sifted key), so the expected sifting rate is 1/2.

An intercept-resend eavesdropper measures in a random basis. With probability 1/2 she guesses the basis (no error); otherwise she sends back a photon in the wrong basis and Bob, if his basis matches Alice's, errs with probability 1/2. Per intercepted photon the sifted error is 1/2 × 1/2 = 1/4. If she attacks a fraction f, and the channel also flips Bob's bit with probability e:

Q = a(1−e) + (1−a)e,  a = f/4

The simulated sifted bits are binomial, so the measured QBER has standard error σ = √(Q(1−Q)/nsift). The in-page check passes when the measurement lies within 3σ of Q and the sifted fraction within 3√(1/4N) of 1/2. Random numbers come from a seeded generator, so a run is reproducible; a different seed gives a different sample.

The key-fraction line uses the asymptotic Shor–Preskill bound r = max(0, 1 − 2h2(Q)) and the usual ~11% abort threshold. These are textbook asymptotic values for ideal single-photon sources; real systems add decoy states, finite-size penalties, multi-photon pulses and error-correction leakage.

Simplifications: single photons, perfect detectors, no loss, an attack that is only the textbook intercept-resend one, and a bit-flip channel standing in for misalignment and dark counts. Noise alone looks the same as an eavesdropper: Alice and Bob cannot tell them apart, they simply discard the key. This is an educational model of the protocol's statistics.