Quantum Computation & Cryptography · Lecture 20

Lecture 20
Quantum Key Distribution: BB84 and E91

Week 11  |  using the fragility of quantum states as a burglar alarm, and what it does and does not protect  |  reading: de Wolf, Quantum Computing: Lecture Notes, QKD chapter; Bennett and Brassard (1984)

Cartoon: the eavesdropper's dilemmaAlice on the left sends photons along a fiber to Bob on the right. Eve crouches in the middle holding a detector, and a thought bubble above her says: if I look, they will see I looked. AliceBobEve if I look, theysee I looked
measurement disturbs, and copying is impossible: the two facts from Lectures 4 and 8 that QKD turns into security
In this lecture
  1. The key-distribution problem
  2. BB84
  3. Eavesdropping leaves fingerprints
  4. Deciding whether to continue: a hypothesis test
  5. From raw key to secret key
  6. E91: keys from entanglement
  7. QKD in the real world, and QKD versus PQC
  8. Try it in code
  9. Summary and exercises

Block II ended with Shor's algorithm breaking the public-key cryptography that distributes keys on the internet (Lecture 17). The standard answer is post-quantum cryptography: new public-key schemes based on problems believed hard even for quantum computers. This lecture is about the other answer, which uses quantum mechanics itself. By the end you should be able to run the BB84 protocol by hand, explain why an eavesdropper must cause errors and compute how many, decide from a sample of errors whether to continue or abort, describe the classical post-processing that turns a noisy shared string into a secret key, explain how E91 uses Bell violations, and say clearly what QKD does and does not provide.

1 — The key-distribution problem

The one-time pad is perfectly secure: to send an \(m\)-bit message \(x\), Alice sends \(x\oplus k\) for a uniformly random key \(k\) of the same length, used once. Anyone without \(k\) sees uniformly random bits. Symmetric ciphers like AES are a practical version: a short shared key encrypts long messages. Either way, Alice and Bob first need a shared secret key, and getting one to each other over a public network is exactly what RSA and Diffie–Hellman do today, and what Shor's algorithm breaks.

Classically, a key sent over a channel can be copied by an eavesdropper without leaving a trace. Quantum mechanics changes that in two ways we already know. An unknown quantum state cannot be copied (the no-cloning theorem, Lecture 8). And measuring a state in the wrong basis changes it (Lecture 4): a \(Z\) measurement of \(|+\rangle\) leaves \(|0\rangle\) or \(|1\rangle\), not \(|+\rangle\). So an eavesdropper who wants to learn something must interact with the qubits, and an interaction that extracts information disturbs them. Quantum key distribution (QKD) turns that disturbance into an alarm.

2 — BB84

definition 20.1 — the BB84 protocol (Bennett and Brassard, 1984)

Alice and Bob share a quantum channel (in practice, single photons in an optical fiber) and an authenticated public classical channel: everyone can listen, but nobody can alter messages undetected.

  1. Send. For each round, Alice picks a random bit \(a\) and a random basis \(A\in\{Z,X\}\), and sends \(|a\rangle\) if \(A=Z\) (that is \(|0\rangle\) or \(|1\rangle\)) or \(H|a\rangle\) if \(A=X\) (\(|+\rangle\) or \(|-\rangle\)).
  2. Measure. Bob picks a random basis \(B\in\{Z,X\}\) and measures, getting a bit \(b\).
  3. Sift. Over the public channel, Alice and Bob announce their bases (not their bits) and keep only the rounds with \(A=B\). The kept bits form the sifted key.
  4. Estimate the error rate. They compare a random sample of sifted bits publicly, estimate the quantum bit error rate (QBER) \(Q\), discard the sample, and abort if \(Q\) is too large.
  5. Reconcile and amplify. They correct the remaining errors by public discussion (information reconciliation) and shorten the result with a random hash function (privacy amplification), obtaining the final secret key.

When \(A=B\) and nobody interferes, Bob's measurement returns Alice's bit with certainty. When \(A\ne B\), he measures \(|0\rangle\) in the \(X\) basis (or \(|+\rangle\) in the \(Z\) basis) and gets a fair coin flip, which is why those rounds are discarded. Since the bases are independent and uniform, sifting keeps half the rounds on average.

In one round Alice picks bit 1 and basis \(X\), so she sends \(|-\rangle\). Bob measures in \(Z\) and gets 0. Nobody is eavesdropping. What happens to this round?

Compare the two bases first. What does a \(Z\) measurement of an \(X\)-basis state return?
\(A=X\ne B=Z\), so the round is thrown away when the bases are announced. Bob's 0 was a coin flip and says nothing about Alice's bit.

Suppose Alice and Bob each choose \(Z\) with probability 0.9 and \(X\) with probability 0.1, independently. What fraction of the rounds survives sifting?

A round is kept when both choose \(Z\) or both choose \(X\). The choices are independent, so multiply within each case and add.
\(0.9^2+0.1^2=0.82\). Biased basis choices waste fewer rounds than the uniform \(\tfrac12\); the test in the rare basis then needs care.
Twelve rounds of BB84A table of twelve BB84 rounds, generated by a seeded simulation without an eavesdropper. Rows: Alice's bit, Alice's basis (Z or X), the state sent, Bob's basis, Bob's result, whether the round is kept after sifting, and the key bit. Bases agree in rounds 4, 6, 8, 9, 10 and 11, which are kept; there Bob's results equal Alice's bits, giving the sifted key 1 1 1 0 0 0. In the other six rounds Bob's result is a coin flip and is discarded.round123456789101112Alice bit110111110001Alice basisZXXZXZZXZZZZsent|1>|->|+>|1>|->|1>|1>|->|0>|0>|0>|1>Bob basisXZZZZZXXZZZXBob result100101110000kept?---yes-yes-yesyesyesyes-key bit111000
Twelve rounds of BB84 with no eavesdropper (seeded simulation, verify_L20.py). Six rounds have matching bases (shaded) and are kept; in all six, Bob's result equals Alice's bit. In the other six his results (grey) are coin flips and are thrown away. The sifted key is 111000.

Notice what is announced and what is not. The bases become public, but only after Bob has measured. Why this order matters, and what Eve gains from the announcement, is part of HW10 Problem 3.

3 — Eavesdropping leaves fingerprints

The simplest attack is intercept and resend: Eve catches a qubit, measures it in a basis of her choice, and sends Bob a fresh qubit in the state she observed. If she guesses Alice's basis, nothing changes; if not, her measurement destroys Alice's state and Bob's result, even in a sifted round, is a coin flip.

proposition 20.1 — the price of intercept-resend

If Eve intercepts each qubit with probability \(f\), measures it in a uniformly random basis (\(Z\) or \(X\)) and resends the result in her basis, then each intercepted sifted round has an error with probability \(\tfrac14\), and the QBER is \(Q=f/4\).

Proof: HW10 Problem 3.

A quick check before reading on.

On a noiseless channel, Alice and Bob measure a QBER of 6% and attribute all of it to a random-basis intercept-resend attack. According to Proposition 20.1, what fraction \(f\) of the qubits did Eve intercept?

Invert Proposition 20.1: solve \(Q=f/4\) for \(f\). (An answer of 0.06 forgets the factor \(\tfrac14\).)
\(f=4Q=4\cdot0.06=0.24\): Eve touched about a quarter of the qubits. Since only a quarter of her intercepted sifted rounds show an error, the QBER understates how much she looked by a factor of 4.

Is a random basis Eve's best choice? She cannot do better at hiding than leaving qubits alone, but among attacks that measure every qubit she can trade disturbance for information. The next example shows that the disturbance of intercept-resend is stubborn: changing her basis changes what she learns, not how much she disturbs.

example 20.1 — measuring halfway between the bases

Eve measures every qubit in the Breidbart basis \(|e_0\rangle=\cos\tfrac\pi8|0\rangle+\sin\tfrac\pi8|1\rangle\), \(|e_1\rangle=-\sin\tfrac\pi8|0\rangle+\cos\tfrac\pi8|1\rangle\), whose Bloch vectors lie halfway between \(\pm\hat z\) and \(\pm\hat x\). She resends \(|e_k\rangle\) when she sees \(k\), and guesses that Alice's bit was \(k\). Find the QBER and the probability that Eve's guess is right, on sifted rounds.

Take a sifted round in the \(Z\) basis with \(a=0\) (the other three cases are the same by symmetry: the Breidbart basis sits at \(\pi/4\) on the Bloch sphere from both \(\hat z\) and \(\hat x\)). Eve sees \(k=0\) with probability \(\cos^2\tfrac\pi8\) and \(k=1\) with probability \(\sin^2\tfrac\pi8\). Bob, measuring \(|e_0\rangle\) in \(Z\), errs with probability \(\sin^2\tfrac\pi8\), and measuring \(|e_1\rangle\), with probability \(\cos^2\tfrac\pi8\). So

$$Q=\cos^2\tfrac\pi8\sin^2\tfrac\pi8+\sin^2\tfrac\pi8\cos^2\tfrac\pi8=\tfrac12\sin^2\tfrac\pi4=\tfrac14 ,$$

the same disturbance as the random-basis attack. But Eve's guess is right with probability \(\cos^2\tfrac\pi8\approx0.854\), better than the random-basis attack achieves (HW10 Problem 3 asks you to compute that). Her information about each bit went up; Alice and Bob's alarm rang just as loudly.

idea — information versus disturbance

The general principle, which security proofs make quantitative, is that any information Eve gains about the key bits is paid for by errors that Alice and Bob can measure. In the limit of no errors Eve has no information. Alice and Bob therefore treat the measured error rate as an upper limit on what Eve may know, and the post-processing of Section 5 removes as much information as she could possibly have.

BB84 simulator

Each column of the panel is one round: Alice's bit and basis, what Eve does (if anything), Bob's basis and result. Shaded columns survive sifting; rose marks are errors. The readout summarizes a run of many rounds: the QBER, how often Eve's guess of the sifted bits is right (for the Breidbart attack), and the secret fraction \(1-2h(Q)\) of Section 5.

4 — Deciding whether to continue: a hypothesis test

Alice and Bob never know \(Q\); they estimate it from a random sample of \(n\) sifted bits, which they then throw away. The decision "continue only if \(Q\) is below a threshold \(Q_{\max}\)" is a one-sided hypothesis test of the kind met in introductory statistics: errors in the sample are \(\mathrm{Bin}(n,Q)\), and Alice and Bob continue only if the data make \(Q\ge Q_{\max}\) implausible. Equivalently, they continue if a one-sided upper confidence bound for \(Q\) is below \(Q_{\max}\). Section 5 explains why \(Q_{\max}\approx11\%\) for BB84.

A sample of \(n=600\) sifted bits contains 24 errors. Find the one-sided 95% upper confidence bound for \(Q\) with the normal approximation.

\(\hat Q=24/600\), standard error \(\sqrt{\hat Q(1-\hat Q)/n}\), and the one-sided 95% multiplier is 1.645.
\(\hat Q=0.04\), standard error \(\sqrt{0.04\cdot0.96/600}=0.008\), bound \(0.04+1.645\cdot0.008\approx0.0532\): comfortably below 11%, so they continue.
example 20.2 — 30 errors in 400

Alice and Bob compare \(n=400\) sifted bits and find 30 disagreements. Compute a one-sided 95% upper confidence bound for \(Q\) with the normal approximation and exactly (Clopper–Pearson). Do they continue, with \(Q_{\max}=11\%\)?

\(\hat Q=30/400=0.075\), standard error \(\sqrt{0.075\cdot0.925/400}\approx0.0132\). Normal bound: \(0.075+1.645\cdot0.0132\approx0.0967\). The exact Clopper–Pearson bound, the \(Q\) with \(P(\mathrm{Bin}(400,Q)\le30)=0.05\), is about \(0.1004\) (scipy.stats.beta.ppf(0.95, 31, 370)). Both are below 0.11, so they continue; but the exact bound is noticeably closer to the threshold.

The test bits cost key: every compared bit is discarded. Real systems sample a small fraction of a very long sifted key, so that \(n\) is in the tens of thousands and the bound is tight. The finite-size statistics of QKD (bounding \(Q\) on the unsampled bits, which is a sampling-without-replacement problem) are an active part of security proofs.

5 — From raw key to secret key

After sifting and estimation, Alice and Bob hold strings that (i) differ in a fraction \(Q\) of positions and (ii) are partly known to Eve. Two classical steps fix each problem.

Information reconciliation. Alice and Bob correct their differences by exchanging parities over the public channel. In the simplest scheme (the idea behind the Cascade protocol), they split the key into blocks and compare each block's parity; when a block's parities differ, it contains an odd number of errors, and a binary search on parities of halves finds one error. For an 8-bit block with one error this reveals 4 parities: the block's and three halvings (see the code in Section 8). Every revealed parity is information Eve also hears, at least \(h(Q)\) bits per key bit in the best case (Shannon's bound), where

$$h(Q)=-Q\log_2Q-(1-Q)\log_2(1-Q)$$

is the binary entropy. Modern systems use LDPC error-correcting codes for this, the same kind of code that appears in Lecture 23.

A 16-bit block contains exactly one error. How many parities does the block-parity-plus-binary-search scheme reveal before the error is located?

One parity for the whole block shows that it has an odd number of errors; then each comparison of a half's parity halves the search interval.
\(1+\log_2 16=1+4=5\) parities, each heard by Eve. That leakage is what privacy amplification must later remove.

Privacy amplification. Eve may know some bits of the corrected key, or some parities of it. Alice and Bob apply a random hash function that compresses the key to a shorter string; if the output is short enough, Eve's partial information about the input says almost nothing about the output.

definition 20.2 — universal hashing; Toeplitz matrices

A family of functions \(\{0,1\}^n\to\{0,1\}^m\) is universal if for any two different inputs \(x\ne x'\), a randomly chosen member maps them to the same output with probability at most \(2^{-m}\). A random \(m\times n\) binary Toeplitz matrix \(T\) (constant along each diagonal, so determined by \(n+m-1\) random bits), applied as \(x\mapsto Tx\bmod2\), is a universal family. The leftover hash lemma says that if Eve's uncertainty about \(x\) is at least \(m+2\log_2(1/\varepsilon)\) bits (in the sense of min-entropy), then \(Tx\) is within \(\varepsilon\) of uniform even given Eve's information and \(T\).

Alice and Bob hash 10 bits down to 3 with a random \(3\times10\) Toeplitz matrix. How many random seed bits must Alice announce, and what is the largest possible probability that two given different inputs hash to the same output?

A Toeplitz matrix is fixed by its first row and first column, which share one entry. Universality bounds the collision probability by \(2^{-m}\).
\(n+m-1=10+3-1=12\) seed bits, and collisions happen with probability at most \(2^{-3}=\tfrac18\), as for a truly random function.
example 20.3 — hashing 8 bits down to 4

Alice and Bob agree on the 8-bit key \(x=10110010\), and Alice announces 11 random seed bits defining the \(4\times8\) Toeplitz matrix below. Compute the final key \(Tx\bmod2\).

$$T=\begin{pmatrix}1&0&0&1&0&0&0&1\\0&1&0&0&1&0&0&0\\0&0&1&0&0&1&0&0\\0&0&0&1&0&0&1&0\end{pmatrix}$$

Each output bit is the parity of the key bits where its row has a 1. Row 1 picks positions 1, 4, 8: \(1+1+0=0\). Row 2 picks 2, 5: \(0+0=0\). Row 3 picks 3, 6: \(1+0=1\). Row 4 picks 4, 7: \(1+1=0\). The final key is \(0010\). The matrix is public, yet This 8-bit example only shows the mechanics; at this size there is no security guarantee (if Eve knew bits 2 and 5, she would know output bit 2 exactly). The leftover hash lemma promises that the \(m\) output bits are within \(\varepsilon\) of uniform and independent of Eve only when Eve's uncertainty about the input (its min-entropy) is at least \(m+2\log_2(1/\varepsilon)\). In practice \(n\) is millions of bits and \(\varepsilon\) around \(10^{-10}\), so the margin \(2\log_2(1/\varepsilon)\approx67\) bits is negligible.

How much secret key survives? For BB84 with one-way post-processing, the Shor–Preskill security proof (2000) gives, for long keys, a secret fraction of

$$r(Q)=1-2h(Q)$$

of the sifted key: one \(h(Q)\) is paid for reconciliation and one for privacy amplification. It vanishes at \(h(Q)=\tfrac12\), that is \(Q\approx11.0\%\). That is where the 11% threshold comes from. In Example 20.2, using the exact upper bound \(Q\le0.1004\), the secret fraction is \(1-2h(0.1004)\approx0.059\): about 6 secret bits per 100 sifted bits (8 with the normal bound), against 23 per 100 if \(Q=7.5\%\) were known exactly: statistical uncertainty is expensive near the threshold.

Find the asymptotic secret fraction \(r(Q)=1-2h(Q)\) at a QBER of 3%.

\(h(0.03)=-0.03\log_2 0.03-0.97\log_2 0.97\). Note \(\log_2 0.03\approx-5.06\) and \(\log_2 0.97\approx-0.044\).
\(h(0.03)\approx0.194\), so \(r\approx1-0.389=0.611\): even a 3% error rate costs almost 40% of the sifted key.
How much error each protocol toleratesTwo panels against the QBER Q from 0 to 0.2. Left: the asymptotic secret-key fraction of BB84 with one-way post-processing, 1 - 2 h(Q), where h is the binary entropy; it starts at 1, is 0.43 at Q = 5%, and reaches 0 at Q = 11.0%, beyond which no key can be extracted this way. Right: the CHSH value S = 2 sqrt 2 (1 - 2Q) of a Bell pair mixed with white noise; it falls from 2.83 and crosses the classical bound 2 at Q = 14.6%.BB84: 1 - 2h(Q)00.250.50.7510.000.050.100.150.20QBER Q11.0%secret fractionE91: S = 2 sqrt2 (1 - 2Q)1.522.530.000.050.100.150.20QBER Q14.6%CHSH Sclassical bound 2
Left: the secret-key fraction of BB84 against the QBER; it falls fast and reaches zero at 11.0%. Right: the CHSH value of a Bell pair degraded by white noise (Section 6) crosses the classical bound 2 at a QBER of 14.6%.

6 — E91: keys from entanglement

In 1991 Artur Ekert proposed a protocol in which a source, which might even be controlled by Eve, sends one qubit of each Bell pair \(|\Phi^+\rangle\) to Alice and the other to Bob. Each measures in a randomly chosen basis. On rounds where their bases agree, their outcomes are perfectly correlated (Lecture 6) and form the key. On the other rounds they use bases at the CHSH angles of Lecture 8 and compute the CHSH value \(S\).

The CHSH value certifies security. Quantum mechanics allows \(S\) up to \(2\sqrt2\approx2.83\), reached only by a maximally entangled pair, which can have no correlation with anything else (entanglement is monogamous). Any attack that gives Eve classical information about the outcomes lowers \(S\); a local hidden-variable model, which is what Eve's full knowledge would amount to, gives \(S\le2\). For a Bell pair mixed with white noise, \(\rho=v|\Phi^+\rangle\langle\Phi^+|+(1-v)I/4\), the QBER is \(Q=(1-v)/2\) and

$$S=2\sqrt2\,v=2\sqrt2\,(1-2Q),$$

which drops below 2 at \(Q=\tfrac12\big(1-\tfrac1{\sqrt2}\big)\approx14.6\%\) (verify_L20.py checks both formulas on the density matrix). Lab 2 measured \(S\) for real.

An E91 source produces \(\rho=v|\Phi^+\rangle\langle\Phi^+|+(1-v)I/4\) with \(v=0.8\). Find the QBER and the expected CHSH value.

Use \(Q=(1-v)/2\) and \(S=2\sqrt2\,v\).
\(Q=0.1\) and \(S\approx2.263\gt2\): the Bell test still certifies entanglement, and the QBER is just under BB84's 11% threshold.
idea — device-independent QKD

The CHSH test does not depend on how the devices work, only on the observed statistics. So E91-style protocols can, in principle, be proved secure even if Alice's and Bob's measurement devices were built by Eve: this is device-independent QKD, first demonstrated in 2022 over short distances, at very low key rates. It answers the main practical objection to QKD (Section 7), at a large cost in rate.

7 — QKD in the real world, and QKD versus PQC

What QKD needs that the theory assumes.

Tick every assumption that QKD's security actually rests on.

Re-read the three bullet points above: which of the listed items appear there as requirements, and which as things QKD cannot do?
Authentication and honest hardware are the two assumptions; hardness of factoring and limits on Eve's memory are not needed, and amplifiers are not available.

Where it is used. China operates a QKD backbone of about 2,000 km between Beijing and Shanghai with trusted nodes, connected to the Micius satellite; there are metropolitan networks in Europe, Korea and Japan. In New York, a 34 km deployed-fiber loop between Brooklyn and Manhattan distributed polarization-entangled photon pairs continuously for 15 days with about 99% fidelity and 99.84% uptime (Craddock et al., PRX Quantum, 2024): the kind of infrastructure that entanglement-based QKD and future quantum networks need.

crypto connection — QKD versus PQC

The U.S. National Security Agency states that it does not recommend QKD for national security systems unless its limitations are overcome: it is only a partial solution (no authentication), needs special-purpose equipment rather than software, depends on trusted relays, is hard to validate because its security is "highly implementation-dependent rather than assured by laws of physics", and raises denial-of-service risk. The U.K.'s NCSC and several European agencies have published similar positions. All of them recommend post-quantum cryptography (Lecture 17) as the primary migration path. QKD's supporters answer that its security does not rest on unproven hardness assumptions, which matters for secrets that must stay secret for decades. A fair summary: PQC is the near-term migration for the internet; QKD is a niche technology for specific high-value links, where the hardware can be controlled, and a research program toward device-independent and network-scale security.

8 — Try it in code

tool — BB84 with qiskit circuits (stabilizer simulator)
import numpy as np
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator

sim = AerSimulator(method="stabilizer", seed_simulator=20)      # X, H and measurements are Clifford: 64 qubits is easy
rng = np.random.default_rng(2020); n = 64

def send_and_measure(bits, send_bases, meas_bases):
    """Prepare |bit> in each send basis (0 = Z, 1 = X) on n qubits, measure each in meas_bases; return the bits read."""
    qc = QuantumCircuit(n, n)
    for q in range(n):
        if bits[q]: qc.x(q)
        if send_bases[q]: qc.h(q)
        if meas_bases[q]: qc.h(q)
        qc.measure(q, q)
    key = next(iter(sim.run(qc, shots=1).result().get_counts()))
    return np.array([int(c) for c in key[::-1]])                # Qiskit lists qubit 0 last

a, A, B = rng.integers(0, 2, n), rng.integers(0, 2, n), rng.integers(0, 2, n)
b = send_and_measure(a, A, B)                                   # no Eve
keep = A == B
print(f"no Eve:   sifted {keep.sum()} of {n}, errors {np.sum(a[keep] != b[keep])}")
E = rng.integers(0, 2, n)
e = send_and_measure(a, A, E)                                   # Eve measures every qubit in a random basis...
b = send_and_measure(e, E, B)                                   # ...and resends what she saw, in her basis
print(f"with Eve: sifted {keep.sum()} of {n}, errors {np.sum(a[keep] != b[keep])}, QBER {np.mean(a[keep] != b[keep]):.3f}")
print("first 8 sifted rounds  Alice:", a[keep][:8], " Bob:", b[keep][:8])
no Eve:   sifted 27 of 64, errors 0
with Eve: sifted 27 of 64, errors 4, QBER 0.148
first 8 sifted rounds  Alice: [1 1 1 0 1 1 1 1]  Bob: [1 1 1 0 0 1 1 0]

All the operations are Clifford (\(X\), \(H\), measurement), so Aer's stabilizer simulator handles 64 qubits at once. With only 27 sifted bits the error count is very noisy: 4 errors where \(27/4\approx7\) are expected. HW10 Problem 5 simulates BB84 statistically, without circuits, to get QBER curves.

tool — reconciliation, privacy amplification and the key rate
import numpy as np

def h(q): return 0.0 if q in (0, 1) else -q * np.log2(q) - (1 - q) * np.log2(1 - q)

# information reconciliation: find one error in an 8-bit block by comparing parities of halves
alice = [1, 0, 1, 1, 0, 0, 1, 0]; bob = [1, 0, 1, 0, 0, 0, 1, 0]
lo, hi, revealed = 0, 8, 1                                      # the whole-block parity was compared first
while hi - lo > 1:
    mid = (lo + hi) // 2; revealed += 1
    if sum(alice[lo:mid]) % 2 != sum(bob[lo:mid]) % 2: hi = mid
    else: lo = mid
bob[lo] ^= 1
print("error at position", lo, " parities revealed:", revealed, " keys agree:", alice == bob)

# privacy amplification: hash the 8 agreed bits to 4 with a random Toeplitz matrix (11 public seed bits)
rng = np.random.default_rng(20)
seed = rng.integers(0, 2, 11)
T = np.array([[seed[i - j + 7] for j in range(8)] for i in range(4)])
print("Toeplitz matrix:\n", T)
print("final key:", T @ np.array(alice) % 2)

# asymptotic secret fraction of the sifted key, r = 1 - 2 h(Q)
for Q in (0.01, 0.05, 0.075, 0.0967, 0.11):
    print(f"QBER {Q:.4f}: secret fraction {1 - 2 * h(Q):+.4f}")
error at position 3  parities revealed: 4  keys agree: True
Toeplitz matrix:
 [[1 0 0 1 0 0 0 1]
 [0 1 0 0 1 0 0 0]
 [0 0 1 0 0 1 0 0]
 [0 0 0 1 0 0 1 0]]
final key: [0 0 1 0]
QBER 0.0100: secret fraction +0.8384
QBER 0.0500: secret fraction +0.4272
QBER 0.0750: secret fraction +0.2314
QBER 0.0967: secret fraction +0.0831
QBER 0.1100: secret fraction +0.0002

Example 20.3 and the key-rate formula of Section 5. At the 11% threshold the secret fraction is essentially zero.

9 — Summary and exercises

summary

Next time: protecting quantum information itself from noise, with quantum error-correcting codes. HW10 (Lectures 18–20) is due at the start of Week 12; project proposals are due this week.

exercises 20
  1. Eve intercepts 20% of the qubits with the random-basis attack. What QBER do Alice and Bob expect?
  2. In a sample of 1,000 sifted bits there are 30 errors. Give the normal-approximation one-sided 95% upper bound for \(Q\).
  3. Compute the asymptotic secret fraction \(1-2h(Q)\) at \(Q=5\%\). Out of \(10^6\) rounds sent, about how many secret bits is that?
  4. Compute \(Tx\bmod2\) for the matrix of Example 20.3 and \(x=11110000\). Which input bits does output bit 3 depend on?
  5. In E91 with a QBER of 5% from white noise, what CHSH value do Alice and Bob expect?
  6. Eve measures every qubit in the \(Z\) basis (always) and resends. Find the QBER on sifted rounds where Alice used \(Z\), on those where she used \(X\), and overall. How could Alice and Bob detect this attack more quickly than by the overall QBER?
  1. \(0.2/4=5\%\).
  2. \(0.03+1.645\sqrt{0.03\cdot0.97/1000}\approx0.0389\).
  3. \(h(0.05)\approx0.2864\), so \(1-2h\approx0.427\). Sifting keeps about \(5\times10^5\) of the \(10^6\) rounds, so about \(2.1\times10^5\) secret bits (fewer in practice: test bits, finite-size corrections, and photon loss, which in a real fiber removes most rounds before sifting).
  4. Rows pick positions \(\{1,4,8\}\), \(\{2,5\}\), \(\{3,6\}\), \(\{4,7\}\): parities \(1+1+0=0\), \(1+0=1\), \(1+0=1\), \(1+0=1\), so \(0111\). Output bit 3 depends on input bits 3 and 6.
  5. \(S=2\sqrt2\,(1-0.1)\approx2.55\), comfortably above 2.
  6. Rounds where Alice used \(Z\): Eve measures in the right basis and resends Alice's state, so no errors. Rounds where Alice used \(X\): Eve's \(Z\) measurement randomizes the \(X\) value, so Bob errs half the time. Overall \(\tfrac12\cdot0+\tfrac12\cdot\tfrac12=\tfrac14\). Alice and Bob should estimate the QBER separately in each basis: a QBER of 50% in one basis and 0 in the other is a glaring signature that a combined figure of 25% would hide among other causes.

Reading and sources

all numbers and figures in these notes are computed in python (verify_L20.py) and follow the page theme