Project 9: Quantum Key Distribution (BB84 Protocol)

Build a BB84 simulation that generates a shared secret key.


Project Overview

Attribute Value
Difficulty Level 2: Intermediate
Time Estimate Weekend
Main Language Python
Alternative Languages Java, C++
Knowledge Area Quantum security
Tools Simulator or simple math model
Main Book “Quantum Computation and Quantum Information” by Nielsen & Chuang

What you’ll build: A simulator that implements BB84 steps: encoding, measurement, basis reconciliation, and key extraction.

Why it teaches quantum: BB84 shows how measurement guarantees security.

Core challenges you’ll face:

  • Modeling random basis choices
  • Simulating measurement outcomes
  • Detecting eavesdropping via error rates

Real World Outcome

You will generate a shared key and compute the error rate between sender and receiver.

Example Output:

$ python bb84.py --n 1000
Raw key length: 1000
Sifted key length: 480
Error rate: 2.4%

Verification steps:

  • Confirm sifted key lengths near 50% of raw
  • Inject eavesdropping and observe error spike

The Core Question You’re Answering

“How can quantum measurement make eavesdropping detectable?”

BB84 is the simplest practical quantum security protocol.


Concepts You Must Understand First

Stop and research these before coding:

  1. Quantum bases
    • Why do different bases produce different outcomes?
    • Book Reference: Nielsen & Chuang, Ch. 2
  2. No-cloning theorem
    • Why can’t an eavesdropper copy quantum states?
    • Book Reference: Nielsen & Chuang, Ch. 12
  3. Error rate thresholds
    • How do you detect an intercept-resend attack?
    • Book Reference: “Introduction to Quantum Cryptography” by Scarani et al., Ch. 2

Questions to Guide Your Design

  1. Noise modeling
    • Will you include channel noise in addition to eavesdropping?
    • How will you separate noise from attack signals?
  2. Key extraction
    • Will you implement privacy amplification or stop at sifting?
    • How will you report final key rate?

Thinking Exercise

Basis Mismatch

If Alice sends 0 in the Z basis and Bob measures in the X basis, what is the outcome distribution?

Questions while working:

  • Why does basis mismatch cause randomness?
  • How does this protect security?

The Interview Questions They’ll Ask

Prepare to answer these:

  1. “What is the BB84 protocol?”
  2. “Why does measuring in the wrong basis randomize outcomes?”
  3. “How do you detect eavesdropping?”
  4. “What is the no-cloning theorem?”
  5. “What is privacy amplification?”

Hints in Layers

Hint 1: Starting Point Simulate basis choices with random bits.

Hint 2: Next Level Compute sifted key by keeping only matching bases.

Hint 3: Technical Details Inject an eavesdropper that measures randomly to raise error rate.

Hint 4: Tools/Debugging Plot error rate vs eavesdropper presence.


Books That Will Help

Topic Book Chapter
BB84 basics Nielsen & Chuang Ch. 12
No-cloning Nielsen & Chuang Ch. 12
QKD security “Introduction to Quantum Cryptography” by Scarani et al. Ch. 2

Implementation Hints

  • Keep bit arrays explicit for clarity.
  • Track both raw and sifted keys.
  • Run multiple trials to estimate error rate distributions.

Learning Milestones

  1. First milestone: You can simulate BB84 end-to-end.
  2. Second milestone: You can detect eavesdropping via errors.
  3. Final milestone: You can explain the security logic clearly.