Skip to content

Commit

Permalink
Merge pull request #177 from KOSASIH/deepsource-transform-f06fa3f3
Browse files Browse the repository at this point in the history
style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf
  • Loading branch information
KOSASIH authored May 12, 2024
2 parents 9f9ff72 + 31ecb8b commit 122c562
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions security_privacy/security_privacy_manager.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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

0 comments on commit 122c562

Please sign in to comment.