Skip to content

davidgca/qiskit-hackathon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 Quantum Key Distribution (BB84) Simulation

A distributed simulation of the BB84 quantum key distribution (QKD) protocol implemented with Qiskit, FastAPI, Docker, and microservices.
The system reproduces the full communication flow between Alice and Bob, including noisy channels, sifting, error reconciliation (CASCADE-lite + BICONF), and privacy amplification.


🧩 System Architecture

+----------------------------------------------------------+
|                   🐳 Docker Compose                      |
|----------------------------------------------------------|
|                                                          |
|  ┌────────────┐       HTTP/JSON (FastAPI)      ┌────────────┐
|  |   Alice    |  <---------------------------> |    Bob     |
|  |------------|                               |------------|
|  | Qiskit     |-- prepares qubits ----------->| Aer Noise  |
|  | FastAPI    |<-- receives measurements -----| Simulator  |
|  | CASCADE+   |-- /parity, /flip_bit, /confirm| Reconcile  |
|  | BICONF     |-- /privacy_amplify ---------->| /derive_key|
|  └────────────┘                               └────────────┘
|                                                          |
+----------------------------------------------------------+

⚙️ Technologies Used

Component Technology Description
Quantum simulation Qiskit + Qiskit Aer Qubit preparation and measurement with noise models
Backend microservices FastAPI REST endpoints for Alice and Bob
Orchestration Docker + docker-compose Containerized deployment and networking
HTTP Client httpx REST communication between services
Language Python 3.11 Compatible with Qiskit 2.2.x
Optional metrics Prometheus / Grafana Latency and throughput visualization (future)

🧪 BB84 Simulation Workflow

Stage Description Main Endpoints
1. Preparation & Channel Alice prepares random quantum states (Qiskit) and Bob measures them under noise (Aer NoiseModel) /bb84/start (Alice → Bob /measure_from_qasm)
2. Sifting Filters bits with matching bases and uses a 33% sample to estimate QBER /reveal_bits
3. Reconciliation (CASCADE-lite) Error correction via block parity and binary search /parity, /flip_bit
4. Confirmation (BICONF) Universal hash confirmation after each reconciliation pass /confirm
5. Privacy Amplification Key shortening using universal hashing to eliminate leaked information /privacy_amplify
6. Final Key Derivation Bob derives the same final key using identical seed and indices /derive_key

🐳 Quick Start

1️⃣ Build and launch

docker compose up --build

2️⃣ Run the complete flow

2.1 — BB84 start (Preparation & Sifting)

curl -s -X POST 'http://127.0.0.1:8001/bb84/start'   -H 'Content-Type: application/json'   -d '{
        "n": 20000,
        "seed": 42,
        "sample_fraction": 0.33,
        "qber_threshold": 0.11,
        "noise": { "mode": "depolarizing", "qber": 0.03 }
      }' | jq > session.json

2.2 — Interactive Reconciliation (CASCADE + BICONF)

jq '{session_id, kept_indices, raw_alice_kept} + {
      "block":1024, "rounds":2, "permute_seed":123,
      "confirm_tag_bits":64, "confirm_tag_seed":2025
    }' session.json | curl -s -X POST 'http://127.0.0.1:8001/reconcile_interactive'   -H 'Content-Type: application/json'   -d @- | jq > recon.json

2.3 — Privacy Amplification and Summary

jq -n --argfile recon recon.json --argfile sess session.json   '{
     reconciled: $recon.reconciled,
     target_bits: 4096,
     hash_seed: 999,
     qber_est_sample: $sess.qber_est_sample,
     qber_residual: $recon.qber_residual,
     leakage_bits: $recon.leakage_bits,
     kept_len: $recon.len_reconciled
   }' | curl -s -X POST 'http://127.0.0.1:8001/privacy_amplify'   -H 'Content-Type: application/json'   -d @- | jq > alice_key.json

2.4 — Bob Derives the Same Key

jq -n --argfile sess session.json --argfile recon recon.json   '{
     session_id: $sess.session_id,
     kept_indices_ordered: $recon.final_kept_indices,
     target_bits: 4096,
     hash_seed: 999
   }' | curl -s -X POST 'http://127.0.0.1:8002/derive_key'   -H 'Content-Type: application/json'   -d @- | jq > bob_key.json

2.5 — Verify Equality

diff -q <(jq -r '.final_key_hex' alice_key.json) <(jq -r '.final_key_hex' bob_key.json)   && echo "✅ Keys are identical between Alice and Bob"

📊 Example Output (/privacy_amplify)

{
  "qber_est_sample": 0.031,
  "qber_residual": 0.0,
  "leakage_bits": 120,
  "kept_len_before_pa": 13280,
  "suggested_max_bits": 13152,
  "requested_target_bits": 4096,
  "final_bits_len": 4096
}

🧱 Repository Structure

.
├── alice.py              # Alice service (Qiskit + CASCADE + Privacy Amplification)
├── bob.py                # Bob service (Qiskit Aer + channel + key derivation)
├── Dockerfile            # Base image for both services
├── docker-compose.yml    # Orchestration of microservices
├── requirements.txt      # Python dependencies
└── README_en.md          # This document

🧠 Core Concepts Implemented

  • QBER (Quantum Bit Error Rate): noise level of the quantum channel
  • Sifting: basis matching and partial bit disclosure
  • Reconciliation: interactive error correction via parity exchange
  • BICONF: hash-based confirmation of key consistency
  • Privacy Amplification: compression of the reconciled key using universal hashing
  • Quantum Simulation: Qiskit Aer backend with configurable depolarizing noise

🧰 Configurable Parameters

Parameter Description Example
n Number of qubits simulated 20000
block Block size in reconciliation 1024
rounds Number of reconciliation passes 2
permute_seed Random seed for permutation 123
confirm_tag_bits Length of confirmation hash (BICONF) 64
target_bits Desired length of the final key 4096

⚠️ Notes

  • The simulation uses Qiskit Aer, not actual quantum hardware.
  • The final /reveal_bits step is only used for debug and verification — it would not appear in a real QKD protocol.
  • Ready for future extensions with Prometheus and Grafana for performance metrics.

🚀 Next Steps

  • Integrate Prometheus/Grafana to measure communication latency and throughput
  • Implement full Cascade protocol with adaptive rounds
  • Simulate Eve interception scenarios to test QBER thresholds
  • Evaluate performance and energy efficiency per generated secure bit

👩‍💻 Authors

Developed as part of the Qiskit Hackathon (BB84 Quantum Key Distribution) project.
Focus: Quantum channel simulation, Docker microservices architecture, and performance evaluation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors