Superdense Coding
Send two classical bits with one qubit of a shared Bell pair; all four messages decode without error.
For each message $b_1b_0$, Alice applies $X^{b_0}$ then $Z^{b_1}$ to $q_0$, and Bob decodes with CNOT and H. After decoding, $q_0$ holds bit $b_1$ and $q_1$ holds bit $b_0$, so the printed string ($q_1q_0$) appears reversed; we therefore reverse it with [::-1] to read $b_1b_0$. The example shows why attention to bit order matters when interpreting results.
Requirements: pip install qiskit qiskit-aer. The code runs on your machine or in Colab, not inside WordPress.
Code
from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
sampler = StatevectorSampler(seed=8)
for msg in ["00", "01", "10", "11"]:
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
if msg[1] == "1":
qc.x(0)
if msg[0] == "1":
qc.z(0)
qc.cx(0, 1)
qc.h(0)
qc.measure_all()
counts = sampler.run([qc], shots=100).result()[0].data.meas.get_counts()
decoded = max(counts, key=counts.get)
print("sent", msg, "-> counts", counts, "-> read as b1b0 =", decoded[::-1])
Line-by-line code explanation
| Line | Explanation |
|---|---|
| 1-2 | Imports. |
| 4 | A primitive with seed 8. |
| 5 | Loop over the four messages. |
| 6-8 | A shared Bell pair. |
| 9-10 | X if b0 = 1. |
| 11-12 | Z if b1 = 1. |
| 13-14 | Bob's decoding: CNOT then H. |
| 15 | Measurement. |
| 16 | 100 shots. |
| 17 | The only outcome. |
| 18 | Reverse the string to read b1b0. |
Expected output (from an actual run)
sent 00 -> counts {'00': 100} -> read as b1b0 = 00
sent 01 -> counts {'10': 100} -> read as b1b0 = 01
sent 10 -> counts {'01': 100} -> read as b1b0 = 10
sent 11 -> counts {'11': 100} -> read as b1b0 = 11
The results are deterministic; seed=8.
Try it yourself
Related topics
References
- Charles H. Bennett; Stephen J. Wiesner (1992). Communication via one- and two-particle operators on Einstein-Podolsky-Rosen states. Phys. Rev. Lett. 69(20):2881–2884 doi:10.1103/PhysRevLett.69.2881
- IBM Quantum (2025). Qiskit SDK API documentation. IBM Quantum Documentation quantum.cloud.ibm.com
