QuantumShield: BB84 Quantum Key Distribution
Inspiration
I was fascinated by a critical question: What happens when quantum computers break all our encryption?
Traditional cryptography (RSA, AES) relies on hard math problems. But quantum computers can solve these easily with Shor's algorithm. That's when I discovered BB84 - a protocol where security comes from physics itself, not computation. Any eavesdropper physically disturbs quantum states, automatically revealing their presence.
I wanted to make this cutting-edge quantum cryptography visual, accessible, and demonstrate that unhackable communication is possible today.
What it does
QuantumShield is a full-stack quantum key distribution system that:
- Generates cryptographic keys using Qiskit quantum circuits with Z and X basis states
- Simulates the complete BB84 protocol: qubit preparation, transmission, measurement, sifting, error checking, and key generation
- Detects eavesdroppers in real-time by measuring Quantum Bit Error Rate (QBER)
- Visualizes quantum security through an interactive dashboard showing all protocol steps
- Validates with 120+ tests ensuring quantum behavior is correctly simulated
Users can configure key length, enable/disable eavesdropper simulation, and watch as the system either generates a secure 256-bit key (QBER < 11%) or detects the attack (QBER > 11%).
The key innovation: security isn't based on computational difficulty - it's guaranteed by quantum mechanics. Even with infinite computing power, an eavesdropper cannot avoid detection.
How we built it
Architecture
Backend (Python + FastAPI + Qiskit)
qiskit_qubit.py- Quantum circuit implementation with real state vectorsqiskit_bb84.py- Complete 6-step protocol executioneavesdropper.py- Intercept-resend attack simulationapi/routes.py- REST endpoints for protocol executionutils/- Key conversion (binary/hex) and QBER statistics- 120+ unit tests with pytest
Frontend (React + Vite + Tailwind CDN)
- Real-time protocol execution with loading states
- Interactive dashboard with gradient design
- Statistics cards for transmission, security, and performance metrics
- Key display in binary and hexadecimal formats
Key Implementation Details
Quantum State Preparation
class QiskitQubit:
def __init__(self, basis, bit_value):
self.circuit = QuantumCircuit(1, 1)
if basis == 'Z':
if bit_value == 1:
self.circuit.x(0) # Create |1⟩
else: # X-basis
if bit_value == 1:
self.circuit.x(0)
self.circuit.h(0) # Create |+⟩ or |−⟩
Measurement with Quantum Randomness
def measure(self, measurement_basis):
circuit = self.circuit.copy()
if measurement_basis == 'X':
circuit.h(0) # Rotate to X-basis
circuit.measure(0, 0)
simulator = AerSimulator()
result = simulator.run(circuit, shots=1).result()
return int(list(result.get_counts().keys())[0])
QBER Calculation
$$\text{QBER} = \frac{\text{errors found}}{\text{bits checked}}$$
If QBER > 11%, the protocol aborts and discards the key.
Challenges we ran into
Challenge 1: Understanding Quantum Randomness
Problem: My initial tests kept failing because I expected deterministic results from measurements.
Solution: I learned that quantum measurements are fundamentally probabilistic. When measuring in the wrong basis, results are truly random (50/50). I had to adjust tests to account for statistical variance:
# Instead of: assert result == 0
# Use: assert 400 <= zeros <= 600 # ~50% with variance
This was eye-opening - quantum randomness isn't just theory, it's measurable reality.
Challenge 2: Integrating Eavesdropper with Qiskit
Problem: My eavesdropper class worked with simple qubit objects but not Qiskit's quantum circuits.
Solution: I created an adapter pattern that converts between representations:
# Convert Qiskit qubits → simple qubits for Eve
regular_qubits = [Qubit(q.basis, q.bit_value) for q in qiskit_qubits]
intercepted = eve.intercept(regular_qubits)
# Convert back to Qiskit
qiskit_qubits = [QiskitQubit(q.basis, q.bit_value) for q in intercepted]
This preserved quantum behavior while allowing realistic attack simulation.
Challenge 3: The 11% Threshold Mystery
Problem: I didn't understand why 11% QBER was the magic security threshold.
Solution: Deep dive into information theory revealed that above 11%, you need more bits for error correction than the key itself:
$$\text{If QBER} > 0.11: \quad \text{correction bits} > \text{key bits}$$
The Shannon limit makes higher error rates impossible to correct efficiently.
Challenge 4: Virtual Environment Management
Problem: Initially worked without a virtual environment, causing package conflicts.
Solution: Set up proper Python venv, isolated all dependencies, and created comprehensive requirements.txt. This taught me about professional development practices.
Challenge 5: Tailwind CSS Setup
Problem: npm couldn't initialize Tailwind configuration files properly.
Solution: Used Tailwind CDN for rapid prototyping:
<script src="https://cdn.tailwindcss.com"></script>
Sometimes the "quick" solution is the right solution for hackathon timelines!
Accomplishments that we're proud of
- ✅ 120+ passing tests - Comprehensive validation of quantum behavior, protocol steps, and API endpoints
- ✅ Real Qiskit implementation - Not a simulation mock, actual quantum circuits with state vectors
- ✅ Eavesdropper detection works - Successfully demonstrates quantum security by detecting 50% interception attacks
- ✅ Beautiful, functional dashboard - Makes complex quantum cryptography visual and accessible
- ✅ Production-ready architecture - Clean separation of concerns, RESTful API, proper error handling
- ✅ Educational impact - Explains how quantum cryptography works with real-time visualization
The most rewarding moment was watching the QBER spike from 0% to 12.5% when enabling the eavesdropper - seeing quantum mechanics detect the attack in real-time was magical.
What we learned
Quantum Mechanics Fundamentals
I learned how quantum measurement and the uncertainty principle work in practice:
$$|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$$
Measuring in the wrong basis collapses the superposition randomly - this is BB84's core security feature.
The BB84 Protocol
I implemented all 6 steps:
- Preparation: Alice encodes in Z-basis ($|0\rangle, |1\rangle$) or X-basis ($|+\rangle, |-\rangle$)
- Transmission: Qubits sent through quantum channel
- Measurement: Bob measures in random bases
- Sifting: Keep ~50% where bases matched
- Error Estimation: Calculate QBER
- Privacy Amplification: Generate final secure key
Security Mathematics
For Eve's intercept-resend attack: $$\text{QBER} = p_{\text{intercept}} \times 0.25$$
Eve has 50% chance of wrong basis, causing 50% error when Bob measures = 25% total error rate.
Quantum State Math
The four BB84 states form two orthonormal bases:
$$|0\rangle = \begin{pmatrix} 1 \ 0 \end{pmatrix}, |1\rangle = \begin{pmatrix} 0 \ 1 \end{pmatrix}$$
$$|+\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \ 1 \end{pmatrix}, |-\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \ -1 \end{pmatrix}$$
Key insight: $|0\rangle$ is a 50/50 superposition when measured in X-basis:
$$|0\rangle = \frac{1}{\sqrt{2}}(|+\rangle + |-\rangle)$$
Full-Stack Development
I learned to integrate:
- Backend quantum simulation with frontend visualization
- Async API calls with proper loading/error states
- Comprehensive testing strategies (unit, integration, statistical)
- Professional development practices (venv, git, testing)
What's next for QuantumShield
Short Term
- Circuit visualization - Show quantum gates and operations graphically
- More attack strategies - Implement entanglement-based attacks and quantum cloning attempts
- Cascade protocol - Add proper error correction for higher QBER tolerance
- Performance metrics - Compare execution time vs security level
Long Term
- Real quantum hardware - Connect to IBM Quantum for actual qubit execution
- E91 protocol - Implement entanglement-based QKD (more secure than BB84)
- Quantum repeaters - Simulate long-distance QKD with repeater networks
- Hybrid classical-quantum - Integration with AES/RSA for practical deployment
- Multi-party QKD - Extend beyond two parties (Alice and Bob)
The dream: Make quantum-secure communication accessible to everyone, not just governments and corporations.
Built with ⚛️ quantum mechanics, 💻 modern web tech, and ☕ lots of coffee
Built With
- axios
- fastapi
- git
- github
- javascript
- lucide-react
- pydantic
- pytest
- python
- qiskit
- qiskit-aer
- react
- tailwind-css
- uvicorn
- vite
Log in or sign up for Devpost to join the conversation.