-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
QuantumNexusProtocol/src/cryptography/homomorphic_encryption.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from phe import paillier | ||
|
||
class HomomorphicEncryption: | ||
def __init__(self): | ||
self.public_key, self.private_key = paillier.generate_paillier_keypair() | ||
|
||
def encrypt(self, value): | ||
return self.public_key.encrypt(value) | ||
|
||
def add_encrypted(self, encrypted_value1, encrypted_value2): | ||
return encrypted_value1 + encrypted_value2 | ||
|
||
def decrypt(self, encrypted_value): | ||
return self.private_key.decrypt(encrypted_value) | ||
|
||
# Example usage | ||
if __name__ == "__main__": | ||
he = HomomorphicEncryption() | ||
encrypted_value1 = he.encrypt(10) | ||
encrypted_value2 = he.encrypt(20) | ||
encrypted_sum = he.add_encrypted(encrypted_value1, encrypted_value2) | ||
decrypted_sum = he.decrypt(encrypted_sum) | ||
print(f"Decrypted Sum: {decrypted_sum}") |