A Python Package for Quantum Key Distribution
Project description
QKDpy: Quantum Key Distribution Library
QKDpy is a comprehensive Python library for Quantum Key Distribution (QKD) simulations, implementing various QKD protocols, quantum simulators, and cryptographic tools. It provides an intuitive API similar to NumPy, TensorFlow, and scikit-learn, making quantum cryptography accessible to developers and researchers.
Features
- Quantum Simulation: Simulate qubits, quantum gates (now with individual gate classes for better modularity), multi-qubit states, and measurements (with flexible state collapse for research and visualization)
- QKD Protocols: Implementations of BB84, E92, E91, SARG04, CV-QKD, Device-Independent QKD, HD-QKD, and more
- High-Dimensional QKD: Support for qudit-based protocols with enhanced security and key rates
- Key Management: Advanced error correction and privacy amplification algorithms
- Quantum Cryptography: Quantum authentication, key exchange, and random number generation
- Enhanced Security: Message authentication, key validation, and side-channel protection
- Machine Learning Integration: Optimization and anomaly detection for QKD systems
- Quantum Networks: Multi-party QKD and network simulation capabilities
- Visualization: Advanced tools to visualize quantum states and protocol execution
- Quantum Network Analysis: Tools for analyzing quantum networks and multi-party QKD
- Extensible Design: Easy to add new protocols and features
- Performance: Efficient implementations for simulations
Installation
QKDpy requires Python 3.10 or higher. We recommend using uv for package management:
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone the repository
git clone https://github.com/yourusername/qkdpy.git
cd qkdpy
# Create a virtual environment
uv venv
# Install in development mode
uv pip install -e .
Or using pip with a virtual environment:
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install in development mode
pip install -e .
Quick Start
Here's a simple example of using the BB84 protocol to generate a secure key:
from qkdpy import BB84, QuantumChannel, Qubit
from qkdpy.core import PauliX, Hadamard # Import individual gate classes
# Create a quantum channel with some noise
channel = QuantumChannel(loss=0.1, noise_model='depolarizing', noise_level=0.05)
# Create a BB84 protocol instance
bb84 = BB84(channel, key_length=100)
# Execute the protocol
results = bb84.execute()
# Print the results
print(f"Generated key: {results['final_key']}")
print(f"QBER: {results['qber']:.4f}")
print(f"Is secure: {results['is_secure']}")
# Example of flexible qubit measurement and collapse
q = Qubit.plus() # Qubit in superposition
print(f"Qubit state before measurement: {q.state}")
measurement_result = q.measure("hadamard") # Measure without collapsing internal state
print(f"Measurement result: {measurement_result}")
print(f"Qubit state after measurement (still in superposition): {q.state}")
q.collapse_state(measurement_result, "hadamard") # Explicitly collapse the state
print(f"Qubit state after explicit collapse: {q.state}")
# Example of applying a gate
q_zero = Qubit.zero()
print(f"Qubit state before X gate: {q_zero.state}")
q_zero.apply_gate(PauliX().matrix) # Apply Pauli-X gate
print(f"Qubit state after X gate: {q_zero.state}")
For High-Dimensional QKD:
from qkdpy import HDQKD, QuantumChannel
# Create a quantum channel with some noise
channel = QuantumChannel(loss=0.1, noise_model='depolarizing', noise_level=0.05)
# Create an HD-QKD protocol instance with 4-dimensional qudits
hd_qkd = HDQKD(channel, key_length=100, dimension=4)
# Execute the protocol
results = hd_qkd.execute()
# Print the results
print(f"Generated key: {results['final_key']}")
print(f"QBER: {results['qber']:.4f}")
print(f"Is secure: {results['is_secure']}")
print(f"Dimensional efficiency gain: {hd_qkd.get_dimension_efficiency():.2f}x")
For more examples, see the examples directory.
Advanced Usage
QKDpy also supports advanced protocols and features:
from qkdpy import (
DeviceIndependentQKD,
QuantumKeyManager,
QuantumRandomNumberGenerator,
QuantumNetwork,
HDQKD,
QKDOptimizer
)
# Device-independent QKD
di_qkd = DeviceIndependentQKD(channel, key_length=100)
results = di_qkd.execute()
# Quantum key management
key_manager = QuantumKeyManager(channel)
key_id = key_manager.generate_key("secure_session", key_length=128)
# Quantum random number generation
qrng = QuantumRandomNumberGenerator(channel)
random_bits = qrng.generate_random_bits(100)
# Quantum network simulation
network = QuantumNetwork("Research Network")
network.add_node("Alice")
network.add_node("Bob")
network.add_connection("Alice", "Bob", channel)
key = network.establish_key_between_nodes("Alice", "Bob", 128)
# High-dimensional QKD
hd_qkd = HDQKD(channel, key_length=100, dimension=4)
hd_results = hd_qkd.execute()
# ML-based QKD optimization
optimizer = QKDOptimizer("BB84")
parameter_space = {
"loss": (0.0, 0.5),
"noise_level": (0.0, 0.1)
}
# optimization_results = optimizer.optimize_channel_parameters(
# parameter_space,
# lambda params: simulate_protocol_performance(params),
# num_iterations=50
# )
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
License
QKDpy is licensed under the Apache License 2.0. See LICENSE for the full license text.
Citation
If you use QKDpy in your research, please cite it as described in CITATION.cff.
Code of Conduct
This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code.
Contact
For questions, suggestions, or issues, please open an issue on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qkdpy-0.2.5.tar.gz.
File metadata
- Download URL: qkdpy-0.2.5.tar.gz
- Upload date:
- Size: 79.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62d2ca111751d19d0a1d01ecb70c5cdf6a2c4b8793db316dca2c32915f74e0c6
|
|
| MD5 |
efa7b8935c8c5a20065bf7da336bf545
|
|
| BLAKE2b-256 |
34081c46b3e0a6a8c593726f022aae51ba3f9121327da9381e313dbef7d464f8
|
Provenance
The following attestation bundles were made for qkdpy-0.2.5.tar.gz:
Publisher:
release.yml on Pranava-Kumar/qkdpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qkdpy-0.2.5.tar.gz -
Subject digest:
62d2ca111751d19d0a1d01ecb70c5cdf6a2c4b8793db316dca2c32915f74e0c6 - Sigstore transparency entry: 427728938
- Sigstore integration time:
-
Permalink:
Pranava-Kumar/qkdpy@610eb7301b74464f263663569d23f40e05b9baf3 -
Branch / Tag:
refs/tags/v0.2.5 - Owner: https://github.com/Pranava-Kumar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@610eb7301b74464f263663569d23f40e05b9baf3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file qkdpy-0.2.5-py3-none-any.whl.
File metadata
- Download URL: qkdpy-0.2.5-py3-none-any.whl
- Upload date:
- Size: 101.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c43c03aa3127fb1cc342d435321733d4d12a28cd5c424e4989534ca69e3b17a8
|
|
| MD5 |
4dd221bfa0776e82d0a707d8a69f8881
|
|
| BLAKE2b-256 |
39cff7896df0d67d1ce239a1e54abaef31174eb6f3d8f56e07211d45f0042604
|
Provenance
The following attestation bundles were made for qkdpy-0.2.5-py3-none-any.whl:
Publisher:
release.yml on Pranava-Kumar/qkdpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qkdpy-0.2.5-py3-none-any.whl -
Subject digest:
c43c03aa3127fb1cc342d435321733d4d12a28cd5c424e4989534ca69e3b17a8 - Sigstore transparency entry: 427728943
- Sigstore integration time:
-
Permalink:
Pranava-Kumar/qkdpy@610eb7301b74464f263663569d23f40e05b9baf3 -
Branch / Tag:
refs/tags/v0.2.5 - Owner: https://github.com/Pranava-Kumar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@610eb7301b74464f263663569d23f40e05b9baf3 -
Trigger Event:
push
-
Statement type: