QKeyGuard – Understanding Quantum Key Distribution with BB84

Inspiration

Quantum computing and cybersecurity are two exciting areas of technology. I wanted to explore how quantum mechanics could help detect someone trying to secretly intercept communication.

This motivated me to build QKeyGuard, an interactive simulator based on the BB84 Quantum Key Distribution protocol. My goal was to make the protocol easier to understand by visualizing how quantum states are prepared, measured, and affected by an eavesdropper.

What it does

QKeyGuard simulates communication between three participants:

  • Alice: Generates random bits and encodes them using quantum states.
  • Bob: Measures the received quantum states using independently selected bases.
  • Eve: Acts as an optional eavesdropper using an intercept-and-resend attack.

The project demonstrates the main steps of BB84:

  1. Alice generates random bits and encoding bases.
  2. Alice prepares quantum states using the Z and X bases.
  3. Bob independently selects measurement bases and measures the received states.
  4. Alice and Bob compare their basis choices and retain the matching positions. This is called basis reconciliation and key sifting.
  5. They disclose a random sample of matching bits to estimate the Quantum Bit Error Rate (QBER).
  6. When Eve is enabled, she measures and resends the quantum states, potentially introducing detectable errors.

The interactive dashboard displays the protocol workflow, quantum circuits, measurement results, basis matching, key candidates, and QBER visualizations.

How I built it

I developed QKeyGuard using Python, Qiskit, Qiskit Aer, and Streamlit.

Qiskit and Qiskit Aer are used to construct and simulate quantum circuits for state preparation and measurement. NumPy handles reproducible random bit and basis generation, while Pandas, Matplotlib, and Plotly support result processing and visualizations. Streamlit provides the interactive dashboard.

For Eve's attack, the simulator performs an initial measurement stage and uses Eve's measured result to prepare the state she resends to Bob in a second simulation stage.

The project also includes a Jupyter Notebook, documentation, circuit diagrams, and automated tests.

Results

I tested two scenarios using 512 signals, random seed 84, and a 20% test sample.

  • Without Eve: The disclosed test sample produced 0.0% QBER.
  • With Eve: The disclosed test sample produced 30.6% QBER.
  • Both scenarios had 246 matching-basis positions, with 49 disclosed test bits and 197 remaining key candidates.

The Eve-enabled result exceeded the configured 11% alert threshold, demonstrating how an intercept-and-resend attack can introduce detectable errors.

The theoretical expected sifted-key QBER under full random-basis intercept-and-resend is approximately 25%. Actual finite-sample results can vary.

What I learned

While building this project, I gained practical experience with:

  • Quantum bits (qubits), superposition, and measurement.
  • Computational (Z) and Hadamard (X) bases.
  • Quantum circuit construction and simulation using Qiskit.
  • The BB84 quantum key distribution protocol.
  • Intercept-and-resend attacks and QBER analysis.
  • Building interactive scientific visualizations with Streamlit.
  • Testing reproducible simulations and handling edge cases.

Challenges I faced

One of the main challenges was correctly implementing the BB84 encoding and measurement process using quantum circuits.

Another challenge was modeling Eve's attack accurately: Eve's actual measurement result needed to determine the quantum state resent to Bob.

I also had to distinguish between the QBER calculated from publicly disclosed test bits and the full sifted-key diagnostic QBER available only inside the simulator. This distinction is important for understanding what Alice and Bob can actually estimate in a real protocol.

Limitations and future scope

QKeyGuard is an educational simulator using ideal local quantum circuit simulation. It is not a production-ready cryptographic system and does not generate secure keys for real communication.

It does not implement authenticated classical communication, error correction, privacy amplification, finite-key security proofs, device noise, channel loss, or advanced attack models.

Future improvements could include quantum channel noise, additional eavesdropping strategies, and more advanced QKD analysis.

Conclusion

QKeyGuard helped me explore how quantum measurement can reveal disturbances in a communication channel. By comparing BB84 simulations with and without an eavesdropper, the project makes an important quantum cryptography concept easier to understand through interactive experiments and visualizations.

Built With

  • aer
  • bb84
  • cryptography
  • cybersecurity
  • distribution
  • jupyter
  • key
  • matplotlib
  • notebook
  • numpy
  • pandas
  • plotly
  • python
  • quantmcomputing
  • streamlit
Share this project:

Updates

Submission history