diff --git a/security_privacy/security_privacy_manager.py b/security_privacy/security_privacy_manager.py index 6ce3afb0f..a2bf2a10f 100644 --- a/security_privacy/security_privacy_manager.py +++ b/security_privacy/security_privacy_manager.py @@ -1,7 +1,10 @@ import random + import numpy as np + from security_privacy.homomorphic_encryption import HomomorphicEncryption + class SecurityPrivacyManager: def __init__(self, homomorphic_encryption): self.homomorphic_encryption = homomorphic_encryption @@ -26,13 +29,22 @@ def perform_computations(self, encrypted_data, operations): public_key = self.homomorphic_encryption.public_key for operation in operations: - if operation['operation'] == 'add': - ciphertext1, ciphertext2 = encrypted_data[operation['index1']], encrypted_data[operation['index2']] - encrypted_data[operation['result_index']] = self.homomorphic_encryption.add(public_key, ciphertext1, ciphertext2) - elif operation['operation'] == 'multiply': - ciphertext = encrypted_data[operation['index']] - value = operation['value'] - encrypted_data[operation['result_index']] = self.homomorphic_encryption.multiply(public_key, ciphertext, value) + if operation["operation"] == "add": + ciphertext1, ciphertext2 = ( + encrypted_data[operation["index1"]], + encrypted_data[operation["index2"]], + ) + encrypted_data[operation["result_index"]] = ( + self.homomorphic_encryption.add( + public_key, ciphertext1, ciphertext2 + ) + ) + elif operation["operation"] == "multiply": + ciphertext = encrypted_data[operation["index"]] + value = operation["value"] + encrypted_data[operation["result_index"]] = ( + self.homomorphic_encryption.multiply(public_key, ciphertext, value) + ) return encrypted_data @@ -42,7 +54,9 @@ def decrypt_results(self, encrypted_data, private_key): """ decrypted_data = [] for ciphertext in encrypted_data: - decrypted_value = self.homomorphic_encryption.decrypt(private_key, ciphertext) + decrypted_value = self.homomorphic_encryption.decrypt( + private_key, ciphertext + ) decrypted_data.append(decrypted_value) return decrypted_data