Quantum Communication Advanced Simulation

Alice sends single photons in a random basis. Bob measures in a random basis; only matching-basis photons are kept (sifting). If Eve measures and resends, she guesses the wrong basis half the time and then corrupts a quarter of the sifted bits. Raise Eve's share and watch the error rate climb past the 11% abort line. Educational model of the BB84 protocol, not a security tool.

The science

BB84: Alice encodes a random bit in a random basis (+ or x); Bob measures in a random basis. When bases differ (probability 1/2) his result is random and the bit is discarded during sifting. For an intercept-resend attacker acting on a fraction pe of photons, each attacked sifted bit is wrong with probability 1/4 (Eve picks the wrong basis half the time and then Bob errs half the time). With independent channel flips of probability p, the expected quantum bit error rate is Q = a + p - 2ap with a = pe/4. The page measures Q from Monte Carlo photons and compares it with this formula in standard errors (z-score). Asymptotic secret fraction (Shor-Preskill, one-way post-processing): r = 1 - 2h(Q), h the binary entropy; it reaches zero near Q = 11%.

Simplifications: ideal single-photon source and detectors, no photon-number-splitting attacks, no finite-key penalty, no authentication overhead. Real fibre systems also lose most photons; this model only studies the error statistics.