Real BB84 hardware uses weak coherent laser pulses, not true single-photon sources. Each pulse's photon count n is genuinely Poisson-distributed, drawn here with Knuth's algorithm: P(n;μ) = μⁿe⁻μ⁄n!. Some pulses carry 2+ photons — an eavesdropper (Eve) can silently split one off a multi-photon pulse without disturbing the rest, learning the bit with zero added error. This is the photon-number-splitting (PNS) attack, and it is invisible to plain QBER monitoring.
The fix: Alice randomly sends pulses at several real mean-photon-numbers — a signal μ, a weaker decoy ν, and vacuum (μ=0) — indistinguishable to Eve in transit. For an honest lossy channel with transmittance η = 10−0.2·L/10 and dark-count rate Y₀, the detection (click) probability given n photons is Yn = 1 − (1−Y₀)(1−η)ⁿ, giving a closed-form Gain Q(μ) = Σₙ P(n;μ)Yn = 1 − (1−Y₀)e−μη.
This simulator's Eve runs the textbook PNS strategy: block every pulse with n≤1 outright (safe — no photon reaches Bob to disturb), and forward n≥2 pulses after stealing one copy, at a rate she calibrates so the aggregate signal-intensity Gain matches what an honest channel would produce — fooling anyone watching only the signal statistics. But that one calibration cannot simultaneously match the decoy-intensity Gain, because ν produces a different multi-photon fraction than μ. The mismatch is real and computed live from the actual counts using the Lo–Ma–Chen decoy-state estimator:
Y₁ᴸ = μ/(μν−ν²) · [ Qᵥe^ν − Qμe^μ·(ν²/μ²) − ((μ²−ν²)/μ²)·Y₀ ]
Turn PNS on and watch: Qsignal stays matched to its honest value (the attack is calibrated to hide there), while Qdecoy collapses well below its honest expectation, and the estimated Y₁ crashes toward zero — exposing the attack that single-intensity BB84 would have missed entirely.
- μ / ν sliders — the real intensities Alice mixes into her pulse stream; ν is always kept below μ.
- Distance — sets channel transmittance η via standard 0.2 dB/km fiber loss.
- PNS Attack — toggles Eve's calibrated block-single/forward-multi strategy described above.