The 3D simulator plugs distance, attenuation and μ straight into a closed-form gain/QBER/rate formula and animates photons for show. This 2D version instead runs the actual BB84 protocol photon-by-photon: for every simulated pulse, Alice picks a random bit and a random basis (rectilinear + or diagonal ×), which fixes the photon's polarization angle (0°/90° or 45°/135°). Whether it survives the fiber is a real Bernoulli draw at the channel's click probability; a detected photon is measured at Bob (and, if Eve is on, first intercepted and re-sent by her) using genuine single-photon quantum measurement statistics — Malus's law:
P(outcome = 0 | measurement axis a, photon angle θ) = cos²(θ − a)
Same basis as the photon → cos²(0°)=1, deterministic. Orthogonal basis → cos²(45°)=0.5, a coin flip. A small fixed optical misalignment δ (chosen so sin²δ = 2%, matching the 3D model's e₀) is added to every measurement axis so even matched-basis clicks carry a residual error. Only pulses where Bob's random basis matches Alice's are kept ("sifting"); the QBER and secure key rate below are computed from these actually simulated bit outcomes, not from a formula — and they are verified (standalone Node script, 2M-pulse runs) to converge on the same closed-form values the 3D sim reports, typically within <2% relative gain and QBER agreement.
- Distance / attenuation — shrinks the per-pulse click probability exponentially (10^(−αL/10)), so far fewer of the simulated pulses ever reach the sifting stage.
- Mean photon number μ — raises detection probability, trading against the fixed dark-count floor exactly as in the 3D model.
- Eve (intercept-resend) — really measures each intercepted photon in her own random basis and re-prepares a fresh photon at her outcome's angle before forwarding it. When her basis happens to differ from Alice's (50% of the time), Bob's later measurement — even though his basis matches Alice's — becomes a coin flip: that mechanism alone produces the textbook 25% sifted-key error rate, reproduced here empirically rather than hard-coded.
Top strip: the last ~24 simulated pulses as polarization tickers (arrow = photon angle, ring color = outcome). Bottom chart: empirical QBER and key rate accumulating over all pulses simulated since the last reset, with the closed-form theoretical values overlaid as dashed reference lines.