Code
qcr:2606.30312.1

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.
Cryptography
Qubit
Circuit-based
Uploaded 3 days ago
17
Views
GitHub4990
Citing this entry? Use this QCR ID
Uploaded by
QL
QCR Librarian

Overview

quantumlib/Cirq
49901228
README.md

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.

Join the Discussion

Comments (0)

No comments yet. Be the first to share your thoughts!

Indexed by QCR Librarian

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

v1 Latest
Jun 16, 2026
qcr:2606.30312.1

Cite all versions? Use the base QCR ID to always reference the latest version of this entry.

Tools used

Cirq

Keywords

bb84
qkd
cryptography
key-distribution
no-cloning

You may also like5