Quantum sandbox
Build circuits on up to 5 qubits with H, X, CNOT and more, watch superposition and entanglement, and try BB84 key distribution with an eavesdropper.
Runs on your device. Nothing is uploaded.
Circuit
- H Hadamard: equal superposition of 0 and 1
- X NOT: flips 0 and 1
- Y Z S T rotations and phase shifts
- ● ⊕ control and target: in one column they form CNOT (two ● make a Toffoli)
Result
BB84: quantum key distribution
Alice sends photons with random bits in random bases (+ or ×). Bob measures in random bases, and they keep only the bits where the bases matched. Anyone who measures the photons on the way disturbs them, and that shows up as errors.
| # | Alice bit | Alice basis | Eve basis | Bob basis | Bob bit | Kept |
|---|
What is going on here
The simulator keeps the full state vector: 2n complex amplitudes, one for every possible outcome. Each gate is a small matrix that changes the amplitudes, and the probability of an outcome is the squared size of its amplitude. A normal computer needs twice the memory for every qubit you add, which is exactly why real quantum computers are interesting.
Try H·H: two Hadamard gates bring the qubit back to 0 because the amplitudes for 1 cancel out. That interference is what Shor’s and Grover’s algorithms are built on. The Bell pair gives 00 or 11 half the time each, never 01 or 10: the qubits are entangled, and measuring one tells you the other.
In BB84, an eavesdropper who measures in the wrong basis spoils the photon, so about 25% of the kept bits disagree. Alice and Bob compare part of the key in the open: above about 11% errors, they throw it away. See what quantum computers mean for your own keys in Quantum threat check.
Questions
Is this a real quantum computer?
No. It is an exact simulation in your browser: it stores all 2ⁿ complex amplitudes and applies each gate as a matrix. The results match what an ideal, noise-free quantum computer would give. Real hardware adds noise and errors.
Why only 5 qubits?
Every extra qubit doubles the memory and work a normal computer needs. Five qubits means 32 amplitudes, enough for Bell pairs, GHZ states, a Toffoli gate and interference, while staying instant and easy to read.
How does BB84 detect an eavesdropper?
Measuring a photon in the wrong basis changes it. An eavesdropper guesses the wrong basis half the time, which causes errors in about 25% of the bits Alice and Bob keep. They compare a sample in the open, and if the error rate is too high (about 11% or more), they discard the key.