BB84 Quantum Key Lab

Play Alice, Bob and Eve. Send photons in random bases, sift the matching ones into a key, switch on an eavesdropper or channel noise, and see how the error rate exposes her and how much secret key is left.

Reviewed December 2026. New to this? Start on the Protocol tab and press “Add Eve (100%)”.

#Alice bitAlice basisEve basisBob basisBob bitKept?Check
11+–×0no
21×–+0no
30+–+0yescompared: match
40+–+0yeskept
50+–+0yeskept
60×–+1no
70×–×0yeskept
80+–+0yeskept
91×–+1no
101+–+1yeskept
110×–×0yeskept
121×–+1no
130×–×0yeskept
140×–×0yeskept
150+–+0yescompared: match
161×–×1yeskept
171+–×0no
180×–+0no
190+–+0yescompared: match
201×–+1no
211×–+1no
220×–+1no
231×–+0no
241+–×1no

+ is the rectilinear basis, × the diagonal basis. Bob keeps a bit only when his basis equals Alice’s; the other half are discarded after the bases are announced. Rows marked “compared” are revealed in public and thrown away. “Kept, wrong” shows an error the comparison sample did not happen to catch.

Sifted key

12 bits (50%)

Compared in public

3 bits, 0 wrong

Estimated error rate

0.0% (expected 0.0%)

Verdict

keep: 9 secret bits

A five-minute path

  1. Protocol tab with a clean channel: count the rows where Alice’s and Bob’s bases match. Their bits always agree.
  2. Press “Add Eve (100%)”. Some kept rows now say “MISMATCH”. About a quarter of the compared bits are wrong.
  3. Lower Eve to 30% and raise the photon count. The error rate falls with her share.
  4. Eavesdropper tab: read how fast the chance of escaping shrinks as more bits are compared.
  5. Key rate tab: find where the curve hits zero.
  6. Big run tab: send 5000 photons with 2% noise and see how few secret bits remain.

What the lab does and does not do

  • Ideal single photons, no loss, noise as random bit flips.
  • Eve uses intercept-resend on a chosen share of photons.
  • The final key length comes from the asymptotic formula 1 − 2h(Q), not from running an actual code.
  • The public channel is assumed authenticated.

Reference tables

Computed by the same code as the lab.

What Bob reads, given Alice’s basis and his own.
Alice’s basisBob’s basisBob’s bitKept?
++Alice’s bit, for certainyes
××Alice’s bit, for certainyes
+×0 or 1, 50% eachno
×+0 or 1, 50% eachno
Expected error rate in the sifted key when Eve intercepts a share of the photons, with no other noise.
Share interceptedError rateAbove 11%?
0%0.0%no
10%2.5%no
25%6.3%no
44%11.0%no
50%12.5%yes, abort
75%18.8%yes, abort
100%25.0%yes, abort
Chance that an eavesdropper who intercepts every photon goes unnoticed when m sifted bits are compared.
m(3/4)^m
52.37e-1
105.63e-2
203.17e-3
401.01e-5
801.01e-10
1601.02e-20

Eight guides

Predict, then check

Eve intercepts every photon and the channel is noiseless. What error rate do Alice and Bob see?

25.0%.

Eve intercepts half of the photons and the channel flips 3% of the bits. What is the expected error rate?

14.75%, from e + p − 2ep with e = 12.5% and p = 3%.

30 sifted bits are compared and Eve intercepts everything. How likely is she to get away?

(3/4)^30 = 1.79e-4.

At a 5% error rate, what fraction of the sifted key becomes secret?

0.427, so about 427 of every 1000 sifted bits.

About how many photons must Alice send to get 1000 sifted bits?

About 2000, since only the half with matching bases is kept.

Related on QuantumAtlas

Frequently asked questions

What is BB84?

The first quantum key distribution protocol, proposed by Charles Bennett and Gilles Brassard in 1984. Alice sends photons prepared in random bases, Bob measures in random bases, and they keep the positions where the bases matched.

How does BB84 detect an eavesdropper?

Measuring a photon in the wrong basis disturbs it. An eavesdropper who intercepts every photon causes a 25 percent error rate in the sifted key, which Alice and Bob see when they compare a sample.

Why is only half of the key kept?

Bob guesses the basis, so he is right half the time. The positions where the bases differ give random results and are discarded.

What is the 11 percent limit?

For long keys, the secret fraction 1 − 2h(Q) reaches zero at an error rate near 11 percent. Above it, Alice and Bob abort.

Is the simulation exact?

The quantum part is modelled exactly: the same basis gives the bit, a different basis gives a fair coin. The random choices use a seeded generator, and the simulated error rates were checked against the closed-form values.

Does the lab run real error correction?

No. It uses the asymptotic key-fraction formula to give the final key length. It does not implement an error-correcting code or a hash function.

Can the lab tell me if a real QKD system is secure?

No. It assumes ideal single photons and a simple attack. Real systems have extra weaknesses.

Is BB84 the same as post-quantum cryptography?

No. BB84 uses quantum physics to distribute keys. Post-quantum cryptography is ordinary software based on maths believed to resist quantum computers.

Does the protocol need a secret to start?

It needs an authenticated classical channel, which in practice means a small pre-shared secret or another authentication method.

Where do the photons go?

About half are lost to sifting, some are used for the error estimate, and the rest shrinks further by error correction and privacy amplification.

Sources and further reading

References were written from memory of the original works. Check the originals for exact citations.