English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

BB84 Attack-and-Defense Simulator: A Hands-On Workshop

Forum topic · 小凯 · 2026-11-07

Summary

This hands-on tutorial from the 'From Coins to Error Correction' quantum computing series (post 094) walks readers through building a BB84 quantum key distribution attack-and-defense simulator in code. Acting in turn as sender, receiver, and eavesdropper, the reader reproduces three key numbers from the protocol: a 50% key retention rate after basis sifting, a 25% error rate under full interception, and a roughly 10^-13 probability that full eavesdropping goes undetected when 100 sifted bits are compared. A third experiment covers partial interception (10% of photons, yielding ~2.5% errors), showing how real protocols combine tightened alarm thresholds with privacy amplification. The post also honestly notes simulator limits: pseudo-random numbers carry no physical guarantee, and device side-channel vulnerabilities are not modeled. Key takeaway: QKD security rests on 'guilty until proven innocent'—physics guarantees detection, information theory dilutes residual leakage.

Prerequisites navigation: You need post 071 (BB84 principles and the 25% error rate), 029 (true randomness), 002 (measurement disturbance), and 091 (statistical breathing). > Next post preview: 095, 'Running a Surface Code Cycle on the Simulator.'

BB84 Attack-and-Defense Simulator: A Hands-On Workshop

How does an army learn to fight without going to war? Sand-table wargaming. Cryptography works the same way: the attack and defense of BB84 can be played without optical fiber—a laptop and a few lines of code let you play, in turn, the three roles of sender, receiver, and eavesdropper, and personally 'run out' every number from post 071.

This post is that sand-table manual. The three key numbers from post 071—a retention rate of 50%, a 25% error rate under full eavesdropping, and an escape probability of 10⁻¹³—today all become your own experimental records.

Sand-Table Rules

The working version of the protocol from post 071—operation manuals for the three roles:

  • Sender: for each bit, randomly choose a basis ("+" or "×") and a value (0 or 1), and send the 'polarized photon';
  • Receiver: for each bit, randomly choose a basis to measure in—record (basis, reading);
  • Public discussion: both sides announce their basis sequences (bases only, never values), keeping bits where the bases match—this is the negotiated key;
  • Eavesdropper: wants to read photons in transit—she must choose a basis to measure (without measuring she reads nothing); choosing the wrong basis 'damages' the photon, which she then resends.
  • In the simulator, a 'photon' is a random-number object and 'measurement' is basis-conditional randomness—the physics is replaced by code, but the probabilistic structure is preserved exactly.

    Experiment 1: The No-Eavesdropping Baseline

    The sender sends 1000 photons, no eavesdropping, one run:

  • About 500 bits retained (same-basis rate of 50%—the probability that two random basis choices match);
  • Error rate in the retained segment about 0% (idealized devices in the simulator).
  • This is the health check baseline of a clean link: half the key rate, zero errors. Remember it—the drama of the next experiment depends entirely on the contrast.

    Experiment 2: Full Interception—25% in Action

    The eavesdropper comes online, intercepting and resending every photon. The retained-segment error rate immediately jumps to—about 25%.

    The number from post 071 was run out by hand today, and the accounting can be checked on the spot: the probability she picks the wrong basis is 1/2 × the probability the reading is disturbed given a wrong basis, 1/2 = 1/4. Sender and receiver compare a sample of 100 retained bits: the probability of all matching is (3/4)¹⁰⁰ ≈ 3×10⁻¹³—one escape in a hundred billion attempts. There is no 'low-profile' full-interception option on a quantum link: to read is to be caught.

    Experiment 3: Low-Profile Eavesdropping and 'Guilty Until Proven Innocent'

    A cleverer eavesdropper: intercept only 10% of the photons. The error rate drops to about 2.5%—below the naive alarm line. Has she slipped through?

    This is exactly where real protocol design happens: production systems tighten the alarm line (say, aborting at 1%) and add one final weapon—privacy amplification: both sides publicly 'compress and stir' the negotiated key (a hash operation—that is literally the technical term), so that even if the eavesdropper retained a small amount of information, it gets diluted by the stirring to the point of uselessness.

    The attack and defense thus converge: QKD's security philosophy is 'guilty until proven innocent'—it does not bet on the eavesdropper staying quiet, but assumes any residual leakage below the alarm line exists, then squeezes it dry with information theory. Post 071 said 'physical guarantee'; this post completes the picture: physical guarantee (guaranteed detection) + informational guarantee (diluting the residue) = a complete defense.

    Two Honest Footnotes About the Simulator

    Two footnotes to prevent the sand table from becoming an illusion:

  • The simulator's 'randomness' is pseudo-random (program-generated)—the 'physical guarantee' of post 071 has no physics in the sandbox; only the probabilistic structure is simulated. The true-randomness half (post 029) is supplied by real devices;
  • The simulator does not model device vulnerabilities (an echo of the third filter point in post 071)—the attack history of real systems lives entirely in 'side channels' (defects in detectors and light sources). In the sandbox, Eve can only attack head-on; real-world thieves never attack head-on.
  • Tearing Down the Analogy

    Where the sand table borrows—and where it doesn't:

  • Dissimilarity one: a military sand table's randomness is dice rolls (probabilities set by humans); the BB84 sandbox's randomness is code written by the protocol's designers—it demonstrates 'if the probabilities are thus, the attack and defense are thus,' not 'the physics is thus.' Sand tables teach strategy; real machines teach engineering.
  • Dissimilarity two: the sandbox can be reset infinitely with cost-free trial and error; photons on a real link are destroyed on use (post 028)—intuition cultivated in wargaming can be carried to the battlefield, but operational muscle must be retrained on real devices.

What You Take Home

1. Three numbers run by hand: retention rate 50% (same-basis rate), 25% under full interception (wrong basis × disturbance, 1/2 × 1/2), escape probability 10⁻¹³ (sampling 100 bits)—the numbers of post 071 move from 'memorized' to 'run out'. 2. Attack and defense converge: low-profile eavesdropping can suppress the error rate, but tightened alarm thresholds + privacy amplification work in relay—QKD's philosophy is guilty until proven innocent: physics guarantees detection, information theory dilutes the residue. 3. Two boundaries of the sandbox: pseudo-randomness has no physics, device vulnerabilities are not modeled—simulation teaches strategy, real machines teach engineering (don't confuse the two muscles).

The hook for the next stop: the sandbox protected the key; next stop protects the quantum state itself—running one round of surface-code patrol on the simulator: how stabilizers read, how syndromes point to errors, how corrections are placed—today we take the board of post 055 into our own hands. Post 095: 'Running a Surface Code Cycle on the Simulator.'

Tags

#bb84#quantum-key-distribution#quantum-cryptography#quantum-computing#privacy-amplification#eavesdropping-simulation#tutorial

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/178636928