Light is a transverse electromagnetic wave — its electric field can oscillate along any direction perpendicular to travel. BB84 uses two pairs of polarization directions, called bases. Within a basis, two perpendicular orientations encode bit 0 and bit 1.
+ basis (rectilinear)
Horizontal & vertical polarization
× basis (diagonal)
Diagonal & anti-diagonal polarization
A polarizing beamsplitter perfectly distinguishes the two states within one basis. Measure a +basis photon with a ×basis analyzer and the result is 50/50 random — the photon is forced to "choose." That randomness is what makes eavesdropping detectable.
1 · Choose a message
Each letter is encoded as 5 bits (A = 00000, B = 00001, ..., Z = 11001). About half of the raw bits are discarded (when Alice and Bob roll different bases), so we'll need roughly 2× the message length in raw rounds.
Your message in 5-bit code
Message progress
Each letter is 5 bits. Cells light up as the sifted key grows long enough to encrypt them.
2 · Generate raw bits, one round at a time
Alice (sender)
Red d6 — basis odd → + · even → ×
?
Black d8 — bit 1–4 → 0 · 5–8 → 1
?
Bob (receiver)
Red d6 — basis odd → + · even → ×
?
Eve (eavesdropper)
Eve d6 — basis odd → + · even → ×
?
Roll all the dice (or type real-dice values) to see what the optics do this round.
0 / 0 rounds · 0 sifted bits
"Auto-run" generates rounds at full speed until enough sifted bits exist for the message.
3 · Public basis comparison & sifted key
■ Same basis → keep■ Different basis → discard
Round
Alice basis
Alice bit
Eve basis
Eve bit
Bob basis
Bob bit
Keep?
Rounds
0
Same basis
0
Sifted key
0
Need
0
4 · Encrypt, transmit, decrypt
In real BB84, a separate set of bits would be sacrificed and publicly compared as a test for Eve before encryption. For this demo we just encrypt the message and use Bob's recovered text as the eavesdropping check — if Eve was listening, his decoded message will be garbled.