Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/algorithms/quantum_resistant_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
from scipy.linalg import qr


class NTRUCryptosystem:
def __init__(self, n, q, p, d):
"""
Expand All @@ -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
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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
Expand All @@ -140,5 +143,6 @@ def main():
print("Ciphertext:", ciphertext)
print("Decrypted Message:", decrypted_message)


if __name__ == "__main__":
main()