Please Run demo.py Code to test all the programs as follows:
- NETWORK TRAFFIC CRYPTOGRAPHIC VULNERABILITY DETECTION DEMONSTRATION
- QUANTUM-RESISTANT VULNERABILITY PREDICTION DEMONSTRATION
- INTERACTIVE PARAMETER VISUALIZATION DASHBOARD DEMONSTRATION
- INTEGRATED QUANTUM-RESISTANT AI SECURITY SYSTEM DEMONSTRATION
- QUANTUM-RESISTANT AI SECURITY SYSTEM DEMONSTRATION
The demo.py calls all the above programs and runs seamlessly with Back-up functions incase of errors.
This project represents the intersection of artificial intelligence and post-quantum cryptography, addressing one of the most significant security challenges on the horizon: the threat quantum computers pose to current encryption standards.
Developed by a team of researchers specializing in both machine learning and cryptography, this toolkit demonstrates how AI techniques can optimize, analyze, and validate quantum-resistant cryptographic algorithms. The project focuses on CRYSTALS-Kyber, a lattice-based encryption scheme recently selected by NIST for standardization in the post-quantum era.
What makes this approach unique is its use of genetic algorithms and neural networks to explore the vast parameter space of lattice-based cryptography, finding configurations that maintain security while improving efficiency. The interactive visualization tools provide researchers and security professionals with intuitive ways to understand the complex trade-offs between security, performance, and vulnerability.
This open-source initiative aims to accelerate the transition to quantum-resistant cryptography by making advanced optimization and analysis tools available to the broader security community. As organizations worldwide prepare for the "harvest now, decrypt later" threat, where adversaries collect encrypted data today to decrypt it once quantum computers become sufficiently powerful, tools like these will be essential for ensuring digital communications remain secure in the quantum computing era.
This repository contains AI-driven tools for optimizing, analyzing, and visualizing post-quantum cryptographic algorithms with a specific focus on CRYSTALS-Kyber parameter optimization and vulnerability prediction.
The project leverages artificial intelligence techniques to address three critical aspects of post-quantum cryptography:
- Parameter Optimization: Using genetic algorithms to optimize CRYSTALS-Kyber parameters for an ideal balance of security and efficiency.
- Vulnerability Prediction: Neural network models trained to predict potential vulnerabilities in post-quantum algorithms.
- Interactive Visualization: Interactive dashboards for exploring parameter spaces and security trade-offs.
To run this project, you'll need the following dependencies:
numpy
pandas
matplotlib
tensorflow>=2.0.0
scikit-learn
deap
joblib
- Clone the repository:
git clone https://github.com/yourusername/quantum-resistant-ai.git
cd quantum-resistant-ai- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install the required packages:
pip install -r requirements.txtquantum-resistant-ai/
├── kyber_parameter_optimizer.py # Genetic algorithm for Kyber parameter optimization
├── vulnerability_prediction_model.py # Neural network for vulnerability prediction
├── kyber_visualization_dashboard.py # Interactive visualization dashboard
├── system_integration.py # Complete system integration demonstration
├── examples/ # Example scripts and notebooks
├── model_checkpoints/ # Directory for saved models
├── logs/ # Training logs
└── README.md # This file
To run the parameter optimization, execute:
python kyber_parameter_optimizer.pyThis will:
- Initialize a genetic algorithm optimizer
- Run optimization to find the best parameter configuration
- Compare the optimized parameters with standard Kyber configurations
- Display performance metrics and visualization
=== Best Parameters Found ===
n = 1024, q = 7681, eta = 2, k = 3
=== Performance Metrics ===
Security Level: 209.7 bits
Public Key Size: 1568.8 bytes
Private Key Size: 3169.7 bytes
Encryption Time: 81.56 ms
Decryption Time: 65.25 ms
Overall Fitness Score: 0.8743
To train and test the vulnerability prediction model:
python vulnerability_prediction_model.pyThis will:
- Generate synthetic vulnerability data
- Train a neural network to predict vulnerabilities
- Analyze standard Kyber configurations and compare vulnerability scores
- Visualize the results
You can also analyze custom parameter sets:
from vulnerability_prediction_model import VulnerabilityPredictionModel
# Initialize and train model
model = VulnerabilityPredictionModel()
model.train(num_samples=2000, epochs=50)
# Analyze a custom parameter set
custom_params = {
'n': 1024,
'q': 7681,
'eta': 2,
'k': 3,
'implementation_noise': 0.05 # Lower noise (better implementation)
}
vulnerabilities = model.analyze_parameter_set(custom_params)
print(f"Overall Vulnerability Score: {vulnerabilities['overall_vulnerability']:.4f}")To launch the interactive visualization dashboard:
python kyber_visualization_dashboard.pyThe dashboard provides:
- Real-time parameter adjustment with sliders
- Security level visualization
- Key size comparison
- Performance metrics
- Vulnerability heatmap
- Lattice structure visualization
- Radar chart for configuration comparison
- Use sliders to adjust parameters (n, q, eta, k)
- Select preset configurations from the radio buttons
- View visualizations that update in real-time as parameters change
To run the complete integrated system:
python system_integration.pyThis demonstrates:
- Integration of all components into a unified system
- Simulation of network traffic analysis for cryptographic vulnerabilities
- Automatic parameter optimization based on detected vulnerabilities
- Performance comparison of different configurations
The enhanced vulnerability prediction model offers more advanced features:
from enhanced_vulnerability_prediction_model import VulnerabilityPredictionModel
# Create model with deep architecture
model = VulnerabilityPredictionModel(model_architecture="deep")
# Train with cross-validation
model.train(
num_samples=5000,
epochs=200,
batch_size=64,
data_complexity="complex",
cross_validation=True,
n_folds=5
)
# Generate optimal configuration
optimal_config = model.generate_optimal_configuration(target_security_level=192)
# Perform sensitivity analysis
sensitivity_df = model.parameter_sensitivity_analysis(optimal_config['parameters'])
model.plot_sensitivity_analysis(sensitivity_df)To save a trained model:
model_path, scaler_path = model.save_model("my_vulnerability_model")To load a previously saved model:
new_model = VulnerabilityPredictionModel()
new_model.load_model("my_vulnerability_model_model.h5", "my_vulnerability_model_scaler.pkl")The examples/ directory contains scripts demonstrating specific use cases:
optimize_for_embedded.py- Parameter optimization for resource-constrained devicesanalyze_standard_configs.py- Vulnerability analysis of standard Kyber configurationsparameter_exploration.py- Exploration of parameter space effects on security and performance
- NIST Level 1 (128 bits): Equivalent to AES-128 security
- NIST Level 3 (192 bits): Equivalent to AES-192 security
- NIST Level 5 (256 bits): Equivalent to AES-256 security
- 0.0-0.25: Low vulnerability
- 0.25-0.5: Moderate vulnerability
- 0.5-0.75: High vulnerability
- 0.75-1.0: Critical vulnerability
- The security models used are simplified approximations for demonstration purposes
- In a real-world application, more sophisticated cryptanalytic models would be used
- The vulnerability prediction is based on synthetic data and should be calibrated with real-world cryptanalysis results
- The genetic algorithm parameters can be tuned for specific optimization goals
This project is based on research into applying machine learning and genetic algorithms to post-quantum cryptography, particularly the CRYSTALS-Kyber algorithm selected by NIST for standardization in the post-quantum era.
The approach demonstrated here can help organizations prepare for the "harvest now, decrypt later" threat, where adversaries collect encrypted data today to decrypt it once quantum computers become sufficiently powerful.
Contributions are welcome! Please feel free to submit a Pull Request.
The DEAP library is required for the genetic algorithm component. Install it with:
pip install deapEnsure you call the train() method before attempting to analyze parameters or make predictions:
model = VulnerabilityPredictionModel()
model.train(num_samples=500, epochs=10) # Quick training for testingReduce the number of samples or batch size:
model.train(num_samples=1000, batch_size=32) # Lower values to reduce memory usageThe visualization dashboard is computationally intensive. Close other applications and reduce the complexity:
run_dashboard(reduced_complexity=True)- For faster training on large datasets, enable GPU acceleration through TensorFlow
- Reduce the number of generations for parameter optimization during testing
- Use the
SimpleVulnerabilityModelclass for quick experimentation
- Run the basic optimizer:
python kyber_parameter_optimizer.py- To test with different security targets:
from kyber_parameter_optimizer import KyberParameterOptimizer, SECURITY_LEVEL
# Target NIST Level 1 (128 bits)
optimizer = KyberParameterOptimizer(target_security_level=SECURITY_LEVEL['NIST_1'])
results = optimizer.optimize()
optimizer.visualize_results(results)
# Target NIST Level 5 (256 bits)
optimizer = KyberParameterOptimizer(target_security_level=SECURITY_LEVEL['NIST_5'])
results = optimizer.optimize()
optimizer.visualize_results(results)- To change optimization parameters:
optimizer = KyberParameterOptimizer(
target_security_level=SECURITY_LEVEL['NIST_3'],
population_size=100, # Larger population
generations=50 # More generations
)
results = optimizer.optimize()- Run basic vulnerability analysis:
python vulnerability_prediction_model.py- Test with custom configurations:
from vulnerability_prediction_model import VulnerabilityPredictionModel
model = VulnerabilityPredictionModel()
model.train(num_samples=2000, epochs=20)
# Define configurations to compare
configs = {
'Standard': {'n': 1024, 'q': 3329, 'eta': 2, 'k': 4},
'Alternative': {'n': 1024, 'q': 7681, 'eta': 3, 'k': 3},
'Experimental': {'n': 768, 'q': 8192, 'eta': 2, 'k': 4}
}
# Compare configurations
comparison = model.compare_configurations(configs)
print(comparison)
model.plot_vulnerability_comparison(comparison)- Generate and analyze a synthetic attack scenario:
# Generate a configuration potentially vulnerable to side-channel attacks
vulnerable_config = {
'n': 512,
'q': 3329,
'eta': 5, # Higher noise parameter
'k': 2,
'implementation_noise': 0.3 # Poor implementation quality
}
vulnerabilities = model.analyze_parameter_set(vulnerable_config)
print("Vulnerability Analysis:")
for k, v in vulnerabilities.items():
print(f" {k}: {v:.4f}")- Launch the basic dashboard:
python kyber_visualization_dashboard.py- Test with a trained vulnerability model:
from vulnerability_prediction_model import VulnerabilityPredictionModel
from kyber_visualization_dashboard import run_dashboard
# Create and train a model
model = VulnerabilityPredictionModel()
model.train(num_samples=500, epochs=10) # Quick training
# Launch dashboard with the model
run_dashboard(vulnerability_model=model)- Explore different parameter configurations:
- Start with a standard configuration (like Kyber-512)
- Try increasing
nto 1024 and observe security improvements - Change
qto 7681 and note the effect on key size - Adjust
etaand observe the effect on vulnerability scores
- Run a short simulation:
python system_integration.py- Customize the simulation duration:
from quantum_resistant_security_system import QuantumResistantSecuritySystem
system = QuantumResistantSecuritySystem()
system.run_simulation(duration_seconds=60) # Run for 1 minute- Test the optimized communication demonstration:
system = QuantumResistantSecuritySystem()
system.initialize_components()
performance_data = system.demonstrate_optimized_communication()To add new parameters to the optimization process:
- Modify the
param_rangesdictionary inKyberParameterOptimizer.__init__:
self.param_ranges = {
'n': [256, 512, 768, 1024],
'q': [2048, 3329, 4096, 7681, 8192],
'eta': [2, 3, 4, 5],
'k': [2, 3, 4],
'new_param': [value1, value2, value3] # Add your new parameter
}- Update the
_evaluate_parametersmethod to include the new parameter in fitness calculation
To add new visualizations to the dashboard:
- Add a new method to the
KyberVisualizationDashboardclass - Create a new subplot in the
setup_plotsmethod - Update the visualization in the
update_plotsmethod
Example for adding a new heat map visualization:
def setup_plots(self):
# Existing code...
# Add new heat map
self.ax_new_heatmap = self.fig.add_subplot(self.gs[2, 2])
self.ax_new_heatmap.set_title('Custom Analysis')
def update_plots(self):
# Existing code...
# Update new heat map
self.ax_new_heatmap.clear()
self.ax_new_heatmap.set_title('Custom Analysis')
# Create data for heatmap
custom_data = np.random.rand(5, 5)
im = self.ax_new_heatmap.imshow(custom_data, cmap='viridis')
# Add colorbar
cbar = plt.colorbar(im, ax=self.ax_new_heatmap)
cbar.set_label('Custom Metric')To extend the system with other post-quantum algorithms:
- Create a new optimizer class modeled after
KyberParameterOptimizer - Implement appropriate parameter ranges and evaluation functions
- Add algorithm selection to the dashboard
To benchmark the performance of different configurations:
from quantum_resistant_security_system import QuantumResistantSecuritySystem
system = QuantumResistantSecuritySystem()
system.initialize_components()
# Perform performance testing
performance_results = []
for n in [512, 768, 1024]:
for q in [3329, 7681]:
for k in [2, 3, 4]:
config = {
'name': f"Config_n{n}_q{q}_k{k}",
'params': {'n': n, 'q': q, 'eta': 2, 'k': k}
}
result = system.test_configuration_performance(config)
performance_results.append(result)
# Display results
import pandas as pd
results_df = pd.DataFrame(performance_results)
print(results_df.sort_values('throughput', ascending=False))Planned improvements for future versions:
- Integration with actual CRYSTALS-Kyber implementation for real-world performance testing
- Support for additional post-quantum algorithms (NTRU, Saber, etc.)
- Enhanced machine learning models trained on real cryptanalytic research data
- Web interface for easier access to the visualization dashboard
- Export functionality for optimized parameters to configuration files
- Integration with TLS libraries for protocol-level testing
This project draws inspiration from:
- NIST Post-Quantum Cryptography Standardization Process
- The CRYSTALS-Kyber team's research papers
- Previous work on AI applications in cryptography
- Open-source genetic algorithm and machine learning frameworks
For questions, issues, or contributions, please open an issue on the GitHub repository or contact the project maintainer at adityasrikar131@gmail.com or ask92@duke.edu.
Thank you for using our Quantum-Resistant AI Security Algorithms toolkit. We hope this project helps advance your understanding of post-quantum cryptography and the application of AI techniques to cryptographic security.