BB84 Quantum Key Distribution
Overview
BB84 Quantum Key Distribution
BB84, introduced by Charles Bennett and Gilles Brassard in 1984, was the first quantum key distribution (QKD) protocol and remains the textbook example of quantum cryptography. This Cirq program demonstrates how two parties, Alice and Bob, can establish a shared secret key whose security rests on the laws of quantum mechanics rather than on computational hardness assumptions. Alice generates two random bit strings: one choosing the value to encode and one choosing the basis (rectilinear or diagonal) in which to prepare each qubit. She sends the prepared qubits over a quantum channel, and Bob measures each in an independently chosen random basis. Afterwards they publicly compare basis choices and keep only the bits where their bases matched, yielding a sifted key. The protocol's security follows from the no-cloning theorem and the fact that measuring a qubit in the wrong basis unavoidably disturbs it, so any eavesdropper who intercepts and resends introduces detectable errors. The example simulates the full prepare-and-measure exchange, performs the basis-reconciliation step, and prints the resulting key, illustrating both how the protocol works and why interception is detectable.
Run it
pip install -r requirements.txt
python bb84.py
Source and license
Imported from examples/bb84.py in quantumlib/Cirq at v1.6.1, under the Apache License 2.0. Original authors: The Cirq Developers. The upstream LICENSE is included alongside this example.
This entry was created automatically from publicly available records. QCR links to public sources and only stores repository content where the license permits redistribution.
Versions
Cite all versions? Use the base QCR ID to always reference the latest version of this entry.
Join the Discussion
Comments (0)
No comments yet. Be the first to share your thoughts!