Quantum demos

Eavesdropper

Play Eve, a spy, and try to read a secret key sent on single particles of light without Alice and Bob finding errors.

How BB84 works

Alice wants to share a secret key with Bob: a string of random bits that only the two of them know, which they can then use to lock and unlock messages. She sends it one bit at a time, on single photons, the particles of light. Each photon is one qubit. She packs each bit into a qubit one of two ways, + or ×, picked at random. The way a bit is packed is called its basis, so + and × are the two bases. To read a bit, you must open the qubit, which means to measure it, the same way it was packed. Open it the wrong way, and you get a random bit, and the qubit now holds that random bit.

Bob opens each qubit a random way. Then Alice and Bob say out loud how they packed and opened each one, but not the bits, and keep only the ones that match. Last, they compare half of the kept bits out loud. On a perfect line, these always match, so if any of them differ, someone was listening. A real line adds a little noise, so a real check allows a few errors.

This method is called BB84, after Charles Bennett and Gilles Brassard, who described it in 1984.

You are Eve, the spy. You can catch any qubit, open it, and send a new one on to Bob. But you do not know how Alice packed it until later, and a wrong guess changes the bit Bob gets.

  1. Alice sends Bob a list of qubits. Each one encodes a random bit in a random basis: + = {|0⟩, |1⟩} or × = {|+⟩, |−⟩}.
  2. Bob measures each qubit in a basis that he picks uniformly at random.
  3. On an authenticated public channel, they compare bases, but not bits. They keep only the positions where their bases match.
  4. They reveal some of the kept bits to estimate the error rate. On a noiseless channel these bits always agree, so one error shows an eavesdropper. The unrevealed bits are the raw key.

You are Eve, and you run an intercept-resend attack. The no-cloning theorem stops you from copying a qubit, so you must measure it. A measurement in the wrong basis projects it onto your basis. Alice’s bases stay secret until step three.

BB84 is named for Charles Bennett and Gilles Brassard, who published it in 1984. It was the first quantum key distribution protocol.

Step 1 of 4

Choose which qubits to open

Many rounds

What share of rounds catch Eve?

Run 1,000 rounds at once. Pick how many of the qubits Eve opens, and see what share of rounds catch her and how much of the key she learns.

Eve intercepts each qubit with probability f, in a random basis. Each intercepted qubit that survives sifting shows an error with probability ¼. Compare the detection rate with Eve’s share of the key.

What this shows

A spy cannot copy a qubit and read the copy later. Physics does not allow it. So each qubit that Eve opens is a gamble. Half the time she opens it the wrong way, and then the bit that reaches Bob is a coin flip, so it is wrong half of those times. Half of a half is a quarter: about one in four of the qubits that Eve opens and that Alice and Bob keep leaves a wrong bit.

To learn more of the key, Eve must open more qubits, and each one adds to the chance of getting caught. With more qubits per round, Alice and Bob check more bits, and even a small share of opened qubits shows up.

The no-cloning theorem forbids a unitary U with U|ψ⟩|0⟩ = |ψ⟩|ψ⟩ for all |ψ⟩. So Eve must measure. She picks the wrong basis with probability ½, and then Bob’s result in the sifted basis is uniformly random. Each intercepted qubit that survives sifting has an error probability of ½ · ½ = ¼, so tapping a share f of the qubits gives a QBER of f/4.

Eve’s information and the error rate grow together. For k checked bits and full interception, the chance she goes unseen is (¾)k. Real systems also have channel noise, so they accept a QBER below a threshold, about 11% for BB84, and then run error correction and privacy amplification.

Part 2: attack the hardware

Photon-number splitting

The steps in Part 1 use one photon for each bit. A real laser cannot do that. Each pulse holds a random number of photons, all with the same bit inside. When a pulse holds two or more, Eve keeps one and sends the rest to Bob. She waits until the bases go public, reads her photon the right way, and has the bit. Bob gets a correct bit, so the check finds no errors.

Eve cannot just block the pulses with one photon, which teach her nothing. Bob would notice that fewer photons arrive. But a long fiber loses most of its light anyway, so Bob expects few clicks of his detector. Eve uses this:

  1. She swaps the long fiber for a line that loses no light. Now more photons would reach Bob than he expects.
  2. She blocks pulses with one photon until Bob’s click count drops back to normal.
  3. If the fiber is long enough, she can block every such pulse, and every click Bob gets comes from a pulse she split.

A line with no loss does not exist today. This demo gives it to Eve because quantum key distribution, QKD for short, must stay safe against any spy that the laws of physics allow.

How to play

  1. At brightness 0.50, find the shortest fiber where Eve knows 100% of the kept bits.
  2. Make the laser dimmer, and see how much longer the fiber must be. Dimmer pulses also give Bob fewer clicks, so a key takes longer to build.
  3. Turn on the decoys, which are dimmer pulses that Alice mixes in at random, and send again.

A weak laser pulse has a Poisson photon number with mean μ, and every photon in the pulse holds the same BB84 state. Eve counts photons without measuring the state, stores one photon from each multi-photon pulse, and measures it after sifting. She replaces the fiber, which has a transmittance η at 0.2 dB/km, with a lossless line, and blocks pulses until Bob’s gain equals the expected 1 − e−μη. A lossless line is an idealization, used because the security proof limits Eve only by physics. The model has a perfect detector and no dark counts.

Decoy states use a second mean, here μ/5, on random pulses. Eve can see only the photon number, so each number has one yield for both kinds of pulse. The two gains then limit how much of the key can come from multi-photon pulses.

PhotonsShare of pulsesWhat Eve does

Brightness is an average, and a pulse holds only whole photons. At 0.50, about six pulses in 10 are empty, three hold one photon, and one holds two or more.

Why decoys work: a dim pulse rarely holds a spare photon, and Eve cannot tell it from a normal pulse. An Eve who lets through only pulses with spares passes too few dim pulses, so Bob gets too few decoy clicks.

What this shows

This attack breaks no physics. Eve never copies a photon, because the laser made the spare for her. The security of BB84 holds for single photons, and a real device can send more than one. At brightness 0.5, Eve knows every kept bit once the fiber is about 36 km long, which is between 35 and 40 km on the slider, because loss gives her room to block all of the single photons.

The errors stay at zero through all of this, so the error check is no help. Decoy pulses give Alice and Bob a new thing to measure: a dim pulse holds spare photons far more rarely, so an Eve who feeds Bob on spare photons makes the dim pulses click too rarely.

Decoys also tell Alice and Bob what share of their kept bits came from pulses with spare photons. They cannot prove that no spy was there, so they count that whole share as known to Eve.

Then they run a public math step called privacy amplification. It mixes the bits together into a shorter key, shorter by that share. A spy who knew some of the old bits knows almost nothing about the mixed ones.

Without decoys, they cannot measure the share. They must assume that every pulse with spare photons leaked, which cuts the key so much that a long fiber gives almost none.

Other attacks go after the devices in the same way. Bright light can blind Bob’s detectors, and light sent into Alice’s device can show how she set it for each photon. Each one has its own fix, so QKD hardware needs testing like any other security product.

The attack needs the multi-photon probability to reach the expected gain: 1 − e−μ(1 + μ) ≥ 1 − e−μη. At μ = 0.5, this holds from about 7.2 dB, or 36 km at 0.2 dB/km. Eve then knows the full key, with a QBER of zero. Below that loss, she knows a share equal to the multi-photon probability divided by the gain.

With decoys, the attack above gives a decoy gain near (μd/μ)² of the signal gain, where a true line gives about μd/μ. An Eve who tunes her blocking to match both gains passes the test, but then she holds no more than the honest multi-photon share. Alice and Bob count that whole share as leaked and remove it in privacy amplification, so the key comes only from single photons. This is the GLLP analysis with decoy states, as Hwang proposed in 2003.

Detector blinding and Trojan horse attacks also go after the devices. Measurement-device-independent QKD removes the attacks on the detectors.

Part 3: test the pairs, not the device

A key from linked pairs

Parts 1 and 2 trust Alice’s device to send the photons it should. A faulty or tampered device could send spare photons, as in Part 2, or give away how it was set. In 1991, Artur Ekert found a way to build a key that tests itself.

A source sends out linked pairs of qubits, one qubit of each pair to Alice and one to Bob. Linked, or entangled, means that the two results are tied together, as in the CHSH game. Each of them measures along one of three lines, picked at random. A line is like a basis in Part 1: a way to open the qubit. Alice picks 0°, 45°, or 22.5°, and Bob picks 0°, 22.5°, or −22.5°.

Then they say out loud which line each of them used, but not the results. Each pair has one of three uses:

  • Key: both used the same line, 0° or 22.5°. Their results match, and the bit goes into the key.
  • Test: Alice used 0° or 45°, and Bob used 22.5° or −22.5°. These are the lines of the CHSH game, so they reveal these results and score the game. The pair wins when the results match, except when Alice used 45° and Bob used −22.5°. Then the pair wins when the results differ. Linked pairs win 85.4% of tests, and no plan made ahead wins more than 75%.
  • Thrown away: any other two lines. They neither match nor play the game, so they teach nothing.

Eve reads Bob’s qubits on the way, along one of the two key lines, and sends on a qubit with the result she got. To read a qubit breaks its link, so that pair then acts like a plan made ahead.

How to play

  1. Send the pairs with Eve on every qubit, and compare the win rate with 75%.
  2. Move the slider down, and send a few times at each share. Each run is random, so near the edge Eve is caught in some runs and not others. Find where that happens.
  3. Set the slider to 0%, and see the win rate that only linked pairs reach.

The source emits |Φ⁺⟩ = (|00⟩ + |11⟩) / √2. A line at angle θ measures in the basis {cos θ|0⟩ + sin θ|1⟩, −sin θ|0⟩ + cos θ|1⟩}, so lines a and b give equal results with probability cos²(a − b). These are angles in the real plane, half the angle on the Bloch sphere. Alice picks 0°, 45°, or 22.5°, and Bob picks 0°, 22.5°, or −22.5°, each with probability ⅓.

Equal lines, 0° and 0° or 22.5° and 22.5°, give the key: 2/9 of the pairs. Alice in {0°, 45°} with Bob in {22.5°, −22.5°} is the CHSH test: 4/9 of the pairs, with x = 1 for 45°, y = 1 for −22.5°, and a win when a ⊕ b = x ∧ y, as on the CHSH page. This page discards the other 3/9, and Ekert’s paper revealed those results too. Eve measures Bob’s qubit along 0° or 22.5°, picked at random, and resends the state she found. Her measurement also fixes Alice’s qubit, so the pair becomes a product state. The simulation runs each pair as a two-qubit state vector.

What this shows

The test checks the pairs themselves, not the device that made them. A win rate above 75% shows that at least some results were not fixed before Alice and Bob measured. The closer it comes to 85.4%, the less anyone else, Eve included, can know about the key. At 85.4%, nobody else can know anything.

So Eve could even build the source herself, as long as Alice’s and Bob’s labs leak nothing, their picks of line are truly random, and their detectors miss few photons. The secret then rests on the physics of the pairs, not on trust in the device.

Eve does not have to push the win rate below 75% to get caught. Alice and Bob know that linked pairs win 85.4%, and with thousands of test rounds, a small drop is already too large for chance.

Eve also leaves errors in the key: one key bit in eight when she reads every qubit. So a check like the one in Part 1 would find her too. The test does more than that check. It tells Alice and Bob how much a spy could know, without any trust in the device.

A pair that Eve has measured wins the CHSH game with probability ½ + √2/8 ≈ 67.7%. So a share f gives a win rate of ½ + (√2/4)(1 − f/2), which falls from cos²(22.5°) ≈ 85.4% and crosses the classical ¾ at f = 2 − √2 ≈ 0.59. The key error rate is f/8. Eve knows a share f/2 of the key for sure, the bits where her line matched. On the other bits she read, she guesses right with probability cos²(22.5°) ≈ 85.4%, so she knows more than f/2. With about 4,000 test rounds the standard error of the win rate is about 0.6%, and the page flags a rate more than four standard errors below cos²(22.5°).

This intercept-resend Eve is easy to see. A better attack learns more for the same score, and security proofs bound Eve’s information by the CHSH score alone (Acín and colleagues, 2007). Real protocols do not stop at the first significant drop. They shorten the key by that bound, after error correction, and stop only when no key is left.

A CHSH score near the Tsirelson bound limits what any other system can share with the pairs. This is the monogamy of entanglement, and it is the base of device-independent QKD, which needs no model of the source or the detectors. It does need sealed labs, true random choices, and detectors that miss few photons. Ekert’s 1991 paper used this CHSH test, with three lines on each side, and device-independent QKD first ran in the lab in 2022.

Explain