diff --git a/core/algorithms/quantum_resistant_crypto.py b/core/algorithms/quantum_resistant_crypto.py index ee80722..f0aac76 100644 --- a/core/algorithms/quantum_resistant_crypto.py +++ b/core/algorithms/quantum_resistant_crypto.py @@ -3,6 +3,7 @@ import numpy as np from scipy.linalg import qr + class NTRUCryptosystem: def __init__(self, n, q, p, d): """ @@ -28,7 +29,7 @@ def keygen(self): f = self.poly_ring.random_element() g = self.poly_ring.random_element() F = f * g % self.q - h = F * g^-1 % self.q + h = F * g ^ -1 % self.q public_key = h private_key = (f, g) return public_key, private_key @@ -55,10 +56,11 @@ def decrypt(self, ciphertext, private_key): :return: Decrypted message """ f, g = private_key - a = ciphertext * f^-1 % self.q + a = ciphertext * f ^ -1 % self.q b = a * g % self.q return b + class PolynomialRing: def __init__(self, n, d): """ @@ -121,6 +123,7 @@ def __truediv__(self, a, b): q, r = qr(a.c, b.c) return np.poly1d(q) + def main(): n = 512 q = 2048 @@ -140,5 +143,6 @@ def main(): print("Ciphertext:", ciphertext) print("Decrypted Message:", decrypted_message) + if __name__ == "__main__": main()