Spaces:
Runtime error

dnasafe commited on
Commit
3e9ea04
·
verified ·
1 Parent(s): 4f03df5

add paillier.ciphertext_add

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -5,9 +5,6 @@ from phe import paillier
5
  public_key, private_key = paillier.generate_paillier_keypair(n_length=1024)
6
 
7
  def secure_encoding(input_data):
8
- print("Secure Encoding -- data owner")
9
- print("===============================")
10
-
11
  # Print raw input_data
12
  print("Raw Input Data:", input_data)
13
 
@@ -30,23 +27,23 @@ def secure_encoding(input_data):
30
  print("Encrypted Ciphertext of the First Element:", encrypted_data[0].ciphertext())
31
 
32
  # Perform homomorphic addition to count smokers
33
- encrypted_count = encrypted_data[0]
34
- for i in range(1, len(encrypted_data)):
35
- encrypted_count += encrypted_data[i]
36
 
37
  # Output encrypted count
38
  print("Result is also encrypted")
39
  print("========================")
40
- print("Encrypted Count:", encrypted_count)
41
 
42
  # Send result to the data owner
43
- decrypted_count = private_key.decrypt(encrypted_count)
44
  print("Send result to the data owner")
45
  print("Decrypted Count:", decrypted_count)
46
 
47
  return (
48
  f"Encrypted Ciphertext of the First Element: {encrypted_data[0].ciphertext()}",
49
- f"Encrypted Count: {encrypted_count}",
50
  f"Decrypted Count: {decrypted_count}",
51
  "Data processing is complete. The encrypted data and count have been generated."
52
  )
 
5
  public_key, private_key = paillier.generate_paillier_keypair(n_length=1024)
6
 
7
  def secure_encoding(input_data):
 
 
 
8
  # Print raw input_data
9
  print("Raw Input Data:", input_data)
10
 
 
27
  print("Encrypted Ciphertext of the First Element:", encrypted_data[0].ciphertext())
28
 
29
  # Perform homomorphic addition to count smokers
30
+ encrypted_sum = encrypted_data[0]
31
+ for enc_value in encrypted_data[1:]:
32
+ encrypted_sum = paillier.ciphertext_add(encrypted_sum, enc_value)
33
 
34
  # Output encrypted count
35
  print("Result is also encrypted")
36
  print("========================")
37
+ print("Encrypted Count:", encrypted_sum)
38
 
39
  # Send result to the data owner
40
+ decrypted_count = private_key.decrypt(encrypted_sum)
41
  print("Send result to the data owner")
42
  print("Decrypted Count:", decrypted_count)
43
 
44
  return (
45
  f"Encrypted Ciphertext of the First Element: {encrypted_data[0].ciphertext()}",
46
+ f"Encrypted Count: {encrypted_sum}",
47
  f"Decrypted Count: {decrypted_count}",
48
  "Data processing is complete. The encrypted data and count have been generated."
49
  )