-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_classiq_enhanced.py
More file actions
165 lines (126 loc) Β· 5.18 KB
/
Copy pathtest_classiq_enhanced.py
File metadata and controls
165 lines (126 loc) Β· 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python3
"""
Test script for Classiq-enhanced Luther's Algorithm
Tests all quantum computing features and enhancements
"""
import sys
import os
sys.path.append('.')
from luther_algorithm.luther_algorithm import LuthersAlgorithm
def test_classiq_integration():
"""Test Classiq integration and authentication"""
print("π§ͺ Testing Classiq Integration...")
try:
# Initialize with Classiq backend
luther = LuthersAlgorithm(mode='super', quantum_backend='classiq', use_gpu=False, use_ml=True)
print(f"β
Classiq Available: {luther.classiq_available}")
print(f"β
Security Level: {luther.get_security_level()}")
if luther.classiq_available:
print("β
Classiq authentication successful!")
print(f" Backend: {luther.execution_preferences.backend}")
print(f" Shots: {luther.execution_preferences.num_shots}")
print(f" Timeout: {luther.execution_preferences.timeout_seconds}s")
else:
print("β οΈ Classiq not available, using classical simulation")
return True
except Exception as e:
print(f"β Classiq integration test failed: {e}")
return False
def test_quantum_operations():
"""Test quantum operations"""
print("\nπ§ͺ Testing Quantum Operations...")
try:
luther = LuthersAlgorithm(mode='super', quantum_backend='classiq')
# Test quantum factoring
test_number = 15 # Small number for testing
factors = luther._quantum_factor_parallel(test_number)
print(f"β
Quantum factoring of {test_number}: {factors}")
# Test quantum key distribution
qkd_key = luther.quantum_key_distribution(256)
print(f"β
QKD key generated: {len(qkd_key)} bytes")
# Test quantum machine learning
test_data = [1, 2, 3, 4, 5]
qml_prediction = luther.quantum_machine_learning_predict(test_data, 'classification')
print(f"β
QML prediction: {qml_prediction}")
return True
except Exception as e:
print(f"β Quantum operations test failed: {e}")
return False
def test_encryption_layers():
"""Test multi-layer encryption"""
print("\nπ§ͺ Testing Multi-Layer Encryption...")
try:
luther = LuthersAlgorithm(mode='super', quantum_backend='classiq')
# Test data
test_data = b"This is a test message for quantum-enhanced encryption!"
print(f"Original data: {test_data.decode()}")
print(f"Original size: {len(test_data)} bytes")
# Encrypt
encrypted = luther.encrypt(test_data)
print(f"Encrypted size: {len(encrypted)} bytes")
print(f"Encryption overhead: {len(encrypted) - len(test_data)} bytes")
# Decrypt
decrypted = luther.decrypt(encrypted)
print(f"Decrypted data: {decrypted.decode()}")
# Verify
success = test_data == decrypted
print(f"β
Encryption/Decryption successful: {success}")
return success
except Exception as e:
print(f"β Encryption test failed: {e}")
return False
def test_security_features():
"""Test all security features"""
print("\nπ§ͺ Testing Security Features...")
try:
luther = LuthersAlgorithm(mode='super', quantum_backend='classiq')
# Test homomorphic encryption if available
if luther.homomorphic:
test_data = [1, 2, 3, 4, 5]
encrypted_he = luther.homomorphic_encrypt(test_data)
decrypted_he = luther.homomorphic_decrypt(encrypted_he)
print(f"β
Homomorphic encryption: {decrypted_he}")
# Test zero-knowledge proofs if available
if luther.zk_proofs:
secret = 42
proof = luther.zero_knowledge_proof(secret, None, 'range')
verified = luther.verify_zero_knowledge_proof(proof, None)
print(f"β
Zero-knowledge proof: {verified}")
# Test threshold cryptography
secret = b"Super secret key"
shares = luther.threshold_cryptography(5, 3, secret)
reconstructed = luther.threshold_cryptography(shares, 3)
print(f"β
Threshold cryptography: {reconstructed == secret}")
return True
except Exception as e:
print(f"β Security features test failed: {e}")
return False
def main():
"""Run all tests"""
print("π Starting Classiq-Enhanced Luther's Algorithm Tests")
print("=" * 60)
tests = [
test_classiq_integration,
test_quantum_operations,
test_encryption_layers,
test_security_features
]
passed = 0
total = len(tests)
for test in tests:
if test():
passed += 1
print()
print("=" * 60)
print(f"π Test Results: {passed}/{total} tests passed")
if passed == total:
print("π ALL TESTS PASSED! Your algorithm is quantum-enhanced and ready!")
print("π¬ Features activated:")
luther = LuthersAlgorithm()
print(f" {luther.get_security_level()}")
else:
print("β οΈ Some tests failed. Check your Classiq installation and configuration.")
return passed == total
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)