You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simulates BB84 with random bit and basis generation for Alice and Bob.
Detects eavesdropping by analyzing error rates in a sampled subset.
Runs multiple trials to compute average key length and detection rates.
How It Works
Alice generates random bits and bases (rectilinear or diagonal).
Eve may intercept qubits with a given probability, introducing errors.
Bob measures qubits in random bases.
Alice and Bob publicly compare bases, keeping bits where bases match.
A sample of bits is checked for errors to detect eavesdropping.
Remaining bits form the shared key.
Usage
Run a Single Simulation
fromqkd_simulatorimportquantum_key_distributionn=8# Number of qubitseavesdrop_prob=0.3# Eavesdropping probabilitykey, detected=quantum_key_distribution(n, eavesdrop_prob)
print(f"Shared key: {key}, Eavesdropper detected: {detected}")
Run Multiple Simulation
fromqkd_simulatorimportsimulate_qkdtrials=100n=8eavesdrop_prob=0.3simulate_qkd(trials, n, eavesdrop_prob)
Requirements
Python 3.x
No external libraries required (uses random and statistics from the standard library)
About
A Python-based simulator for the BB84 quantum key distribution protocol, including eavesdropping detection and performance analysis over multiple trials.