top of page
Search

Simulating the BB84 Quantum Key Distribution Protocol

reemasaalahmad
Jul 14
4 min read

Exploring Secure Communication Through Quantum Computing


Quantum computing is changing how we think about information, computation, and cybersecurity. Unlike classical systems, quantum communication uses the principles of quantum mechanics to detect interference and protect sensitive data.


To explore these concepts practically, I developed a simulation of the BB84 Quantum Key Distribution protocol using the IBM Quantum platform. The project demonstrates how two parties can generate a shared encryption key while detecting whether an unauthorized third party has attempted to intercept the communication.



What Is BB84?


BB84 is a quantum key distribution protocol designed to create a secure shared key between two communicating parties, commonly referred to as Alice and Bob.

Instead of sending a completed encryption key directly, Alice transmits quantum states encoded using different measurement bases. Bob measures the received states using randomly selected bases.


After the transmission:


  1. Alice and Bob compare the bases they used.

  2. They keep only the results produced using matching bases.

  3. The remaining values form the shared secret key.

  4. A portion of the key can be compared to check for possible interception.


The security of the process comes from a fundamental property of quantum mechanics: measuring a quantum state can change it. Therefore, if an eavesdropper, traditionally called Eve, intercepts and measures the transmitted qubits, she introduces detectable errors.



Project Objective


The objective of this project was to simulate the main stages of BB84 and understand how quantum principles can support secure communication.


The simulation focused on:


  • Preparing quantum states.

  • Applying quantum gates.

  • Using different encoding and measurement bases.

  • Measuring qubits.

  • Comparing sender and receiver bases.

  • Extracting a shared secret key.

  • Detecting possible eavesdropping through measurement errors.



Building the Quantum Circuit


I used the IBM Quantum Composer to design and visualize the quantum circuit.

Quantum gates were applied to prepare qubits in different states. The Hadamard gate was used when switching between computational and diagonal bases, while measurement operations converted the final quantum states into classical values.


BB84 quantum circuit implementation and state visualization using the IBM Quantum Composer.


The platform made it possible to observe the circuit structure, measurement probabilities, and quantum-state visualizations in one interface. This helped connect the theoretical steps of the protocol with their actual circuit representation.



How the Simulation Works


1. Random Bit Generation

Alice begins by generating a random sequence of classical bits. She also randomly selects an encoding basis for each bit.

Each bit is then represented as a quantum state.


2. Quantum State Preparation

The qubits are prepared using quantum gates based on Alice’s selected bits and bases.

The computational basis represents states such as:

  • ∣0⟩∣0⟩

  • ∣1⟩∣1⟩

The diagonal basis represents superposition states created using the Hadamard gate.


3. Transmission and Measurement

Bob receives the qubits and randomly chooses a measurement basis for each one.

When Bob uses the same basis as Alice, he can recover the original bit correctly. When the bases do not match, the measurement result may be random.


4. Basis Comparison

Alice and Bob publicly compare their selected bases without revealing the actual bit values.

They discard every result where their bases differ. The remaining results form the sifted key.


5. Eavesdropping Detection

To simulate an eavesdropper, Eve can measure the qubits before forwarding them to Bob.

Because Eve does not know the original encoding bases, some of her measurements alter the quantum states. These changes can create differences between Alice’s and Bob’s results.

By comparing part of the sifted key, Alice and Bob can estimate the error rate. A high error rate may indicate that the communication was intercepted.



Challenges


One of the main challenges was translating a theoretical cryptographic protocol into a clear sequence of quantum operations.


The project required careful attention to:

  • The relationship between classical bits and quantum states.

  • The effect of measurement bases.

  • The correct use of Hadamard and measurement gates.

  • The process of filtering mismatched results.

  • The difference between normal measurement uncertainty and errors caused by interception.


Another challenge was understanding that BB84 does not directly encrypt the full message. Instead, it securely generates a key that can later be used with a classical encryption method.



Project Outcome


The simulation successfully demonstrated the core BB84 process:

  • Quantum states were prepared using different bases.

  • Measurement results were generated through quantum circuits.

  • Matching bases were identified.

  • A shared key was extracted.

  • Interception could be represented through increased measurement errors.


The project provided a practical introduction to quantum cryptography and demonstrated how quantum computing platforms can be used to study advanced security concepts.



Future Development


The project could be expanded by:


  • Automating random bit and basis generation.

  • Simulating larger key sequences.

  • Calculating the quantum bit error rate automatically.

  • Comparing results with and without an eavesdropper.

  • Running the circuit on real IBM quantum hardware.

  • Connecting the generated key to a classical encryption algorithm.

  • Building an interactive dashboard to visualize each stage of the protocol.



Conclusion


The BB84 simulation gave me the opportunity to explore quantum computing beyond theoretical definitions. By building the circuit and analyzing the measurement results, I gained a clearer understanding of how quantum states can be used to generate secure encryption keys and reveal unauthorized interception.


This project reflects the growing connection between quantum computing, cybersecurity, and future communication systems.

 
 
 

Comments


click on the icon below to view my CV

CVICON.png
bottom of page