Quantum Sandbox logo

Quantum Sandbox

An Interactive Quantum Circuit Playground

All Lessons Sandbox
Part 3: Algorithms 11 min read

Quantum Cryptography

Quantum mechanics does not just threaten current encryption - it also provides a theoretically unbreakable way to share secret keys. The same physics that makes eavesdropping possible classically makes it detectable quantum mechanically.

Two sides of the quantum cryptography story

Quantum computing and cryptography have a dual relationship. On one side, quantum computers threaten to break current public-key encryption (as we saw with Shor's algorithm in Lesson 12). On the other side, quantum mechanics enables cryptographic protocols that are secure in a fundamentally different way - not based on computational difficulty, but on the laws of physics themselves.

These two aspects require different responses. The threat from Shor's algorithm is addressed by post-quantum cryptography - new mathematical problems that classical computers struggle with and that quantum computers do not have known efficient algorithms for. The opportunity from quantum physics is realized through quantum key distribution - using quantum states to share secret keys in a way that any eavesdropping attempt is detectable. Think of it like upgrading a lock (post-quantum cryptography makes the lock harder for anyone, quantum or classical, to pick) versus using a tamper-evident seal (QKD makes it obvious the instant someone has tried to peek).

Quantum Key Distribution (QKD)

The most famous quantum cryptographic protocol is BB84, invented by Charles Bennett and Gilles Brassard in 1984. It allows two parties, Alice and Bob, to share a secret key - a string of random bits - with a security guarantee rooted in quantum physics, not mathematical assumptions.

The key insight comes from the measurement principle: measuring a qubit in a superposition state disturbs it and collapses it. An eavesdropper (traditionally called Eve) who intercepts qubits to read them will inevitably disturb them - and Alice and Bob can detect this disturbance by comparing a sample of their received bits over a public channel. If there is too much disturbance, they know someone was listening and discard the key.

The protocol is not just a clever trick - its security is mathematically proven under the assumption of quantum mechanics being correct. No amount of computational power can break BB84 security without being detected, because the security does not rely on a mathematical problem being hard. It relies on the physical impossibility of measuring a quantum state without disturbing it.

How BB84 works

Alice generates random bits and randomly chooses from two bases to encode each bit: either the computational basis (|0⟩ and |1⟩) or the diagonal basis (|+⟩ and |−⟩, which are superpositions created by H). She sends the encoded qubits to Bob.

Bob randomly measures each qubit in one of the two bases. About half the time, he chooses the same basis as Alice and gets the correct bit. The other half, his measurement is in the wrong basis and gives a random result.

After Bob receives all qubits, Alice and Bob publicly compare which bases they used (not the actual bits). They keep only the bits where they used the same basis - about half the total. This becomes their shared secret key. It's a bit like Alice flipping a coin and noting heads or tails through one of two different filters, then announcing only which filter she used for each flip - never the actual result - so Bob can tell her which of his guesses used the matching filter, without either of them ever saying the outcome out loud.

If Eve intercepts and measures qubits (she has to guess the basis, just like Bob), she disturbs them. When Bob measures a disturbed qubit correctly, he still gets about 25% errors even in the right basis. Alice and Bob detect this by comparing a subset of their shared bits and checking for unusually high error rates. High errors mean eavesdropping - discard everything and try again.

Try it in the Sandbox
Explore entanglement-based key distribution
  1. Load the Bell State preset. The entangled pair used in E91 key distribution.
  2. Observe: 50% |00⟩ and 50% |11⟩. Alice and Bob's qubits are perfectly correlated.
  3. Click Measure All repeatedly. The results are random, but Alice and Bob always agree.
  4. Any eavesdropper would break the Bell inequality, which are detectable through statistical tests.
  5. Unlike classical key exchange, this relies on physics alone, void of any computational assumptions.

Post-quantum cryptography: protecting against Shor

QKD provides a theoretically perfect solution but requires quantum hardware - fiber or satellite links, quantum light sources, single-photon detectors. This is expensive and not yet globally deployable. The vast majority of internet security cannot wait for quantum networks.

Post-quantum cryptography (PQC) addresses this with new classical algorithms based on mathematical problems that no known quantum algorithm can solve efficiently. NIST's 2024 standardized algorithms include:

CRYSTALS-Kyber (ML-KEM) for key encapsulation, based on the hardness of learning with errors (LWE) - a problem involving finding a solution to a noisy system of equations. It's like trying to recover someone's exact GPS coordinates when every reading you're given has been nudged by a small, random, unknown error - individually each clue is nearly useless, and the noise compounds fast enough that brute-force search (classical or quantum) stays impractical. CRYSTALS-Dilithium (ML-DSA) and FALCON for digital signatures, also based on lattice problems. SPHINCS+ for signatures based on hash functions.

These algorithms run on existing classical hardware and can be deployed in standard software updates. Major technology companies and government agencies are already in the process of migrating to PQC standards.

The cryptographic transition ahead

The transition from current cryptography to post-quantum standards is one of the largest infrastructure upgrades in internet history. Every system that uses public-key cryptography - TLS certificates for websites, VPN protocols, email signing, software updates, financial systems - must eventually be updated.

The good news is that NIST has standardized the algorithms, and the timeline is manageable if the work starts now. The bad news is that "harvest now, decrypt later" attacks mean waiting is not safe - an adversary can record your encrypted traffic today, the way you'd photograph a locked diary, and simply wait for a future quantum computer to pick the lock and read everything inside. Organizations with sensitive long-lived data need to begin the transition immediately.

For you personally: the post-quantum cryptographic migration will be an enormous area of work for security engineers over the next decade. Understanding both the quantum threat and the solutions is a valuable and rare combination of knowledge.

Key takeaway

Quantum cryptography has two faces: quantum key distribution uses the disturbance principle to detect eavesdroppers, providing physically-grounded security. Post-quantum cryptography uses new hard mathematical problems to protect classical internet infrastructure against quantum computers. Both are active and urgent areas of work.

Knowledge check · Question 1 of 4

What is the fundamental physical mechanism that makes eavesdropping detectable in quantum key distribution?

The core principle is that measurement disturbs quantum states. Eve cannot read the qubits without collapsing their superpositions, introducing errors that Alice and Bob can detect by comparing a subset of their received bits and checking for anomalously high error rates.
Knowledge check · Question 2 of 4

In BB84, why do Alice and Bob publicly compare which bases they used, rather than the actual bit values?

Announcing only the bases (not the bits) lets Alice and Bob discard the roughly half of measurements where Bob guessed the wrong basis, while keeping the secret values of the matching-basis bits completely private.
Knowledge check · Question 3 of 4

Why is post-quantum cryptography necessary even though quantum key distribution already offers physics-based security?

QKD needs fiber or satellite links, quantum light sources, and single-photon detectors - infrastructure that cannot be deployed everywhere quickly. Post-quantum cryptography runs on existing classical hardware and can be rolled out through ordinary software updates.
Knowledge check · Question 4 of 4

What makes "harvest now, decrypt later" attacks a present-day concern rather than a future one?

Encrypted data intercepted and stored today remains vulnerable indefinitely - once a future quantum computer can run Shor's algorithm at scale, that stored data can be decrypted retroactively, which is why long-lived sensitive data needs protection now.