From 7db67a8210f7609b87d93a8991e74cb07e041130 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Tue, 26 Nov 2024 14:06:07 +0700 Subject: [PATCH] Create post_quantum_crypto.py --- .../src/cryptography/post_quantum_crypto.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 QuantumNexusProtocol/src/cryptography/post_quantum_crypto.py diff --git a/QuantumNexusProtocol/src/cryptography/post_quantum_crypto.py b/QuantumNexusProtocol/src/cryptography/post_quantum_crypto.py new file mode 100644 index 000000000..ffeb027b4 --- /dev/null +++ b/QuantumNexusProtocol/src/cryptography/post_quantum_crypto.py @@ -0,0 +1,22 @@ +from pqcrypto.kem import saber + +class PostQuantumCrypto: + def __init__(self): + self.public_key, self.private_key = saber.generate_keypair() + + def encrypt(self, message): + ciphertext, shared_secret = saber.encrypt(self.public_key, message) + return ciphertext, shared_secret + + def decrypt(self, ciphertext): + message, shared_secret = saber.decrypt(ciphertext, self.private_key) + return message + +# Example usage +if __name__ == "__main__": + pq_crypto = PostQuantumCrypto() + message = b"Hello, Quantum World!" + ciphertext, shared_secret = pq_crypto.encrypt(message) + print(f"Ciphertext: {ciphertext}") + decrypted_message = pq_crypto.decrypt(ciphertext) + print(f"Decrypted Message: {decrypted_message}")