Skip to content

Commit

Permalink
Create main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 8, 2024
1 parent 27bcc86 commit e2bc413
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions projects/PiHE/crypto/demo/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from crypto.key_manager import KeyManager
from crypto.homomorphic_encryption import HomomorphicEncryption

def main():
key_manager = KeyManager(key_size=2048, ciphertext_size=2048)
key_manager.generate_keys()

he = HomomorphicEncryption(key_manager.get_public_key(), key_manager.get_private_key())

plaintext1 = 5
plaintext2 = 3

ciphertext1 = he.encrypt(plaintext1)
ciphertext2 = he.encrypt(plaintext2)

ciphertext_add = he.add(ciphertext1, ciphertext2)
ciphertext_multiply = he.multiply(ciphertext1, ciphertext2)

decrypted_add = he.decrypt(ciphertext_add)
decrypted_multiply = he.decrypt(ciphertext_multiply)

print(f"Plaintext 1: {plaintext1}")
print(f"Plaintext 2: {plaintext2}")
print(f"Encrypted addition: {decrypted_add}")
print(f"Encrypted multiplication: {decrypted_multiply}")

if __name__ == "__main__":
main()

0 comments on commit e2bc413

Please sign in to comment.