lightphe 0.0.5__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. {lightphe-0.0.5 → lightphe-0.0.6}/PKG-INFO +27 -9
  2. {lightphe-0.0.5 → lightphe-0.0.6}/README.md +26 -8
  3. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/__init__.py +11 -2
  4. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/cryptosystems/OkamotoUchiyama.py +10 -7
  5. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe.egg-info/PKG-INFO +27 -9
  6. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe.egg-info/SOURCES.txt +2 -0
  7. lightphe-0.0.6/requirements.txt +2 -0
  8. {lightphe-0.0.5 → lightphe-0.0.6}/setup.py +2 -1
  9. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_cloud.py +6 -5
  10. lightphe-0.0.6/tests/test_exporting_keys.py +26 -0
  11. {lightphe-0.0.5 → lightphe-0.0.6}/LICENSE +0 -0
  12. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/commons/__init__.py +0 -0
  13. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/commons/logger.py +0 -0
  14. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/commons/phe_utils.py +0 -0
  15. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/cryptosystems/Benaloh.py +0 -0
  16. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/cryptosystems/DamgardJurik.py +0 -0
  17. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/cryptosystems/ElGamal.py +0 -0
  18. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/cryptosystems/EllipticCurveElGamal.py +0 -0
  19. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/cryptosystems/GoldwasserMicali.py +0 -0
  20. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/cryptosystems/NaccacheStern.py +0 -0
  21. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/cryptosystems/Paillier.py +0 -0
  22. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/cryptosystems/RSA.py +0 -0
  23. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/cryptosystems/__init__.py +0 -0
  24. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/elliptic/Weierstrass.py +0 -0
  25. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/elliptic/__init__.py +0 -0
  26. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/models/Algorithm.py +0 -0
  27. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/models/Ciphertext.py +0 -0
  28. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/models/EllipticCurve.py +0 -0
  29. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/models/Homomorphic.py +0 -0
  30. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/models/Tensor.py +0 -0
  31. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe/models/__init__.py +0 -0
  32. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe.egg-info/dependency_links.txt +0 -0
  33. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe.egg-info/requires.txt +0 -0
  34. {lightphe-0.0.5 → lightphe-0.0.6}/lightphe.egg-info/top_level.txt +0 -0
  35. {lightphe-0.0.5 → lightphe-0.0.6}/setup.cfg +0 -0
  36. {lightphe-0.0.5 → lightphe-0.0.6}/tests/__init__.py +0 -0
  37. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_benaloh.py +0 -0
  38. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_damgard.py +0 -0
  39. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_elgamal.py +0 -0
  40. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_ellipticcurveelgamal.py +0 -0
  41. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_goldwasser.py +0 -0
  42. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_naccache.py +0 -0
  43. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_okamoto.py +0 -0
  44. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_paillier.py +0 -0
  45. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_rsa.py +0 -0
  46. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_salary.py +0 -0
  47. {lightphe-0.0.5 → lightphe-0.0.6}/tests/test_tensors.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lightphe
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: A Lightweight Partially Homomorphic Encryption Library for Python
5
5
  Home-page: https://github.com/serengil/LightPHE
6
6
  Author: Sefik Ilkin Serengil
@@ -19,7 +19,7 @@ License-File: LICENSE
19
19
  <div align="center">
20
20
 
21
21
  [![PyPI Downloads](https://static.pepy.tech/personalized-badge/lightphe?period=total&units=international_system&left_color=grey&right_color=blue&left_text=pypi%20downloads)](https://pepy.tech/project/lightphe)
22
- [![Stars](https://img.shields.io/github/stars/serengil/LightPHE?color=yellow&style=flat)](https://github.com/serengil/LightPHE/stargazers)
22
+ [![Stars](https://img.shields.io/github/stars/serengil/LightPHE?color=yellow&style=flat&label=%E2%AD%90%20stars)](https://github.com/serengil/LightPHE/stargazers)
23
23
  [![Tests](https://github.com/serengil/LightPHE/actions/workflows/tests.yml/badge.svg)](https://github.com/serengil/LightPHE/actions/workflows/tests.yml)
24
24
  [![License](http://img.shields.io/:license-MIT-green.svg?style=flat)](https://github.com/serengil/LightPHE/blob/master/LICENSE)
25
25
  [![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dserengil%26type%3Dpatrons&style=flat)](https://www.patreon.com/serengil?repo=lightphe)
@@ -41,11 +41,10 @@ Even though fully homomorphic encryption (FHE) has become available in recent ti
41
41
 
42
42
  - 🏎️ Notably faster
43
43
  - 💻 Demands fewer computational resources
44
- - 📏 Generating smaller ciphertexts
44
+ - 📏 Generating much smaller ciphertexts
45
+ - 🔑 Distributing much smaller keys
45
46
  - 🧠 Well-suited for memory-constrained environments
46
47
  - ⚖️ Strikes a favorable balance for practical use cases
47
- - 🔑 Supporting encryption and decryption of vectors
48
- - 🗝️ Performing homomorphic addition, homomorphic element-wise multiplication and scalar multiplication on encrypted vectors
49
48
 
50
49
  # Installation [![PyPI](https://img.shields.io/pypi/v/lightphe.svg)](https://pypi.org/project/lightphe/)
51
50
 
@@ -177,14 +176,14 @@ However, if you tried to multiply ciphertexts with RSA, or xor ciphertexts with
177
176
 
178
177
  # Working with vectors
179
178
 
180
- You can encrypt the output vectors of machine learning models with LightPHE. These encrypted tensors come with homomorphic operation support.
179
+ You can encrypt the output vectors of machine learning models with LightPHE. These encrypted tensors come with homomorphic operation support including homomorphic addition, element-wise multiplication and scalar multiplication.
181
180
 
182
181
  ```python
183
182
  # build an additively homomorphic cryptosystem
184
183
  cs = LightPHE(algorithm_name="Paillier")
185
184
 
186
185
  # define plain tensors
187
- t1 = [1.005, 2.05, -3.5, 4]
186
+ t1 = [1.005, 2.05, 3.5, 4]
188
187
  t2 = [5, 6.2, 7.002, 8.02]
189
188
 
190
189
  # encrypt tensors
@@ -194,13 +193,32 @@ c2 = cs.encrypt(t2)
194
193
  # perform homomorphic addition
195
194
  c3 = c1 + c2
196
195
 
196
+ # perform homomorphic element-wise multiplication
197
+ c4 = c1 * c2
198
+
199
+ # perform homomorphic scalar multiplication
200
+ k = 5
201
+ c5 = k * c1
202
+
197
203
  # decrypt the addition tensor
198
204
  t3 = cs.decrypt(c3)
199
205
 
200
- for i, tensor in enumerate(t3):
201
- assert abs((t1[i] + t2[i]) - restored_tensor) < 0.5
206
+ # decrypt the element-wise multiplied tensor
207
+ t4 = cs.decrypt(c4)
208
+
209
+ # decrypt the scalar multiplied tensor
210
+ t5 = cs.decrypt(c5)
211
+
212
+ # data validations
213
+ threshold = 0.5
214
+ for i in range(0, len(t1)):
215
+ assert abs((t1[i] + t2[i]) - t3[i]) < threshold
216
+ assert abs((t1[i] * t2[i]) - t4[i]) < threshold
217
+ assert abs((t1[i] * k) - t5[i]) < threshold
202
218
  ```
203
219
 
220
+ Unfortunately, vector multiplication (dot product) requires both homomorphic addition and homomorphic multiplication and this cannot be done with partially homomorphic encryption algorithms.
221
+
204
222
  # Contributing
205
223
 
206
224
  All PRs are more than welcome! If you are planning to contribute a large patch, please create an issue first to get any upfront questions or design decisions out of the way first.
@@ -3,7 +3,7 @@
3
3
  <div align="center">
4
4
 
5
5
  [![PyPI Downloads](https://static.pepy.tech/personalized-badge/lightphe?period=total&units=international_system&left_color=grey&right_color=blue&left_text=pypi%20downloads)](https://pepy.tech/project/lightphe)
6
- [![Stars](https://img.shields.io/github/stars/serengil/LightPHE?color=yellow&style=flat)](https://github.com/serengil/LightPHE/stargazers)
6
+ [![Stars](https://img.shields.io/github/stars/serengil/LightPHE?color=yellow&style=flat&label=%E2%AD%90%20stars)](https://github.com/serengil/LightPHE/stargazers)
7
7
  [![Tests](https://github.com/serengil/LightPHE/actions/workflows/tests.yml/badge.svg)](https://github.com/serengil/LightPHE/actions/workflows/tests.yml)
8
8
  [![License](http://img.shields.io/:license-MIT-green.svg?style=flat)](https://github.com/serengil/LightPHE/blob/master/LICENSE)
9
9
  [![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dserengil%26type%3Dpatrons&style=flat)](https://www.patreon.com/serengil?repo=lightphe)
@@ -25,11 +25,10 @@ Even though fully homomorphic encryption (FHE) has become available in recent ti
25
25
 
26
26
  - 🏎️ Notably faster
27
27
  - 💻 Demands fewer computational resources
28
- - 📏 Generating smaller ciphertexts
28
+ - 📏 Generating much smaller ciphertexts
29
+ - 🔑 Distributing much smaller keys
29
30
  - 🧠 Well-suited for memory-constrained environments
30
31
  - ⚖️ Strikes a favorable balance for practical use cases
31
- - 🔑 Supporting encryption and decryption of vectors
32
- - 🗝️ Performing homomorphic addition, homomorphic element-wise multiplication and scalar multiplication on encrypted vectors
33
32
 
34
33
  # Installation [![PyPI](https://img.shields.io/pypi/v/lightphe.svg)](https://pypi.org/project/lightphe/)
35
34
 
@@ -161,14 +160,14 @@ However, if you tried to multiply ciphertexts with RSA, or xor ciphertexts with
161
160
 
162
161
  # Working with vectors
163
162
 
164
- You can encrypt the output vectors of machine learning models with LightPHE. These encrypted tensors come with homomorphic operation support.
163
+ You can encrypt the output vectors of machine learning models with LightPHE. These encrypted tensors come with homomorphic operation support including homomorphic addition, element-wise multiplication and scalar multiplication.
165
164
 
166
165
  ```python
167
166
  # build an additively homomorphic cryptosystem
168
167
  cs = LightPHE(algorithm_name="Paillier")
169
168
 
170
169
  # define plain tensors
171
- t1 = [1.005, 2.05, -3.5, 4]
170
+ t1 = [1.005, 2.05, 3.5, 4]
172
171
  t2 = [5, 6.2, 7.002, 8.02]
173
172
 
174
173
  # encrypt tensors
@@ -178,13 +177,32 @@ c2 = cs.encrypt(t2)
178
177
  # perform homomorphic addition
179
178
  c3 = c1 + c2
180
179
 
180
+ # perform homomorphic element-wise multiplication
181
+ c4 = c1 * c2
182
+
183
+ # perform homomorphic scalar multiplication
184
+ k = 5
185
+ c5 = k * c1
186
+
181
187
  # decrypt the addition tensor
182
188
  t3 = cs.decrypt(c3)
183
189
 
184
- for i, tensor in enumerate(t3):
185
- assert abs((t1[i] + t2[i]) - restored_tensor) < 0.5
190
+ # decrypt the element-wise multiplied tensor
191
+ t4 = cs.decrypt(c4)
192
+
193
+ # decrypt the scalar multiplied tensor
194
+ t5 = cs.decrypt(c5)
195
+
196
+ # data validations
197
+ threshold = 0.5
198
+ for i in range(0, len(t1)):
199
+ assert abs((t1[i] + t2[i]) - t3[i]) < threshold
200
+ assert abs((t1[i] * t2[i]) - t4[i]) < threshold
201
+ assert abs((t1[i] * k) - t5[i]) < threshold
186
202
  ```
187
203
 
204
+ Unfortunately, vector multiplication (dot product) requires both homomorphic addition and homomorphic multiplication and this cannot be done with partially homomorphic encryption algorithms.
205
+
188
206
  # Contributing
189
207
 
190
208
  All PRs are more than welcome! If you are planning to contribute a large patch, please create an issue first to get any upfront questions or design decisions out of the way first.
@@ -116,8 +116,8 @@ class LightPHE:
116
116
  Returns
117
117
  ciphertext (from lightphe.models.Ciphertext import Ciphertext): encrypted message
118
118
  """
119
- if self.cs.keys.get("private_key") is None:
120
- raise ValueError("You must have private key to perform encryption")
119
+ if self.cs.keys.get("public_key") is None:
120
+ raise ValueError("You must have public key to perform encryption")
121
121
 
122
122
  if isinstance(plaintext, list):
123
123
  # then encrypt tensors
@@ -141,6 +141,9 @@ class LightPHE:
141
141
  if self.cs.keys.get("private_key") is None:
142
142
  raise ValueError("You must have private key to perform decryption")
143
143
 
144
+ if self.cs.keys.get("public_key") is None:
145
+ raise ValueError("You must have public key to perform decryption")
146
+
144
147
  if isinstance(ciphertext, EncryptedTensor):
145
148
  # then this is encrypted tensor
146
149
  return self.__decrypt_tensors(encrypted_tensor=ciphertext)
@@ -243,7 +246,9 @@ class LightPHE:
243
246
  to publicly.
244
247
  """
245
248
  keys = self.cs.keys
249
+ private_key = None
246
250
  if public is True and keys.get("private_key") is not None:
251
+ private_key = keys["private_key"]
247
252
  del keys["private_key"]
248
253
 
249
254
  if public is False:
@@ -255,6 +260,10 @@ class LightPHE:
255
260
  with open(target_file, "w", encoding="UTF-8") as file:
256
261
  file.write(json.dumps(keys))
257
262
 
263
+ # restore private key if you dropped
264
+ if private_key is not None:
265
+ self.cs.keys["private_key"] = private_key
266
+
258
267
  def restore_keys(self, target_file: str) -> dict:
259
268
  """
260
269
  Restore keys from a file
@@ -81,18 +81,21 @@ class OkamotoUchiyama(Homomorphic):
81
81
  Returns:
82
82
  ciphertext (int): encrypted message
83
83
  """
84
- p = self.keys["private_key"]["p"]
84
+
85
85
  g = self.keys["public_key"]["g"]
86
86
  n = self.keys["public_key"]["n"]
87
87
  h = self.keys["public_key"]["h"]
88
88
  r = random_key or self.generate_random_key()
89
89
 
90
- if plaintext > p:
91
- plaintext = plaintext % p
92
- logger.debug(
93
- f"plaintext must be in scale [0, {p=}] but this is exceeded."
94
- "New plaintext is {plaintext}"
95
- )
90
+ # having private key is not a must to encrypt but still if you have
91
+ if self.keys.get("private_key") is not None:
92
+ p = self.keys["private_key"]["p"]
93
+ if plaintext > p:
94
+ plaintext = plaintext % p
95
+ logger.debug(
96
+ f"plaintext must be in scale [0, {p=}] but this is exceeded."
97
+ "New plaintext is {plaintext}"
98
+ )
96
99
  return (pow(g, plaintext, n) * pow(h, r, n)) % n
97
100
 
98
101
  def decrypt(self, ciphertext: int):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lightphe
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: A Lightweight Partially Homomorphic Encryption Library for Python
5
5
  Home-page: https://github.com/serengil/LightPHE
6
6
  Author: Sefik Ilkin Serengil
@@ -19,7 +19,7 @@ License-File: LICENSE
19
19
  <div align="center">
20
20
 
21
21
  [![PyPI Downloads](https://static.pepy.tech/personalized-badge/lightphe?period=total&units=international_system&left_color=grey&right_color=blue&left_text=pypi%20downloads)](https://pepy.tech/project/lightphe)
22
- [![Stars](https://img.shields.io/github/stars/serengil/LightPHE?color=yellow&style=flat)](https://github.com/serengil/LightPHE/stargazers)
22
+ [![Stars](https://img.shields.io/github/stars/serengil/LightPHE?color=yellow&style=flat&label=%E2%AD%90%20stars)](https://github.com/serengil/LightPHE/stargazers)
23
23
  [![Tests](https://github.com/serengil/LightPHE/actions/workflows/tests.yml/badge.svg)](https://github.com/serengil/LightPHE/actions/workflows/tests.yml)
24
24
  [![License](http://img.shields.io/:license-MIT-green.svg?style=flat)](https://github.com/serengil/LightPHE/blob/master/LICENSE)
25
25
  [![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dserengil%26type%3Dpatrons&style=flat)](https://www.patreon.com/serengil?repo=lightphe)
@@ -41,11 +41,10 @@ Even though fully homomorphic encryption (FHE) has become available in recent ti
41
41
 
42
42
  - 🏎️ Notably faster
43
43
  - 💻 Demands fewer computational resources
44
- - 📏 Generating smaller ciphertexts
44
+ - 📏 Generating much smaller ciphertexts
45
+ - 🔑 Distributing much smaller keys
45
46
  - 🧠 Well-suited for memory-constrained environments
46
47
  - ⚖️ Strikes a favorable balance for practical use cases
47
- - 🔑 Supporting encryption and decryption of vectors
48
- - 🗝️ Performing homomorphic addition, homomorphic element-wise multiplication and scalar multiplication on encrypted vectors
49
48
 
50
49
  # Installation [![PyPI](https://img.shields.io/pypi/v/lightphe.svg)](https://pypi.org/project/lightphe/)
51
50
 
@@ -177,14 +176,14 @@ However, if you tried to multiply ciphertexts with RSA, or xor ciphertexts with
177
176
 
178
177
  # Working with vectors
179
178
 
180
- You can encrypt the output vectors of machine learning models with LightPHE. These encrypted tensors come with homomorphic operation support.
179
+ You can encrypt the output vectors of machine learning models with LightPHE. These encrypted tensors come with homomorphic operation support including homomorphic addition, element-wise multiplication and scalar multiplication.
181
180
 
182
181
  ```python
183
182
  # build an additively homomorphic cryptosystem
184
183
  cs = LightPHE(algorithm_name="Paillier")
185
184
 
186
185
  # define plain tensors
187
- t1 = [1.005, 2.05, -3.5, 4]
186
+ t1 = [1.005, 2.05, 3.5, 4]
188
187
  t2 = [5, 6.2, 7.002, 8.02]
189
188
 
190
189
  # encrypt tensors
@@ -194,13 +193,32 @@ c2 = cs.encrypt(t2)
194
193
  # perform homomorphic addition
195
194
  c3 = c1 + c2
196
195
 
196
+ # perform homomorphic element-wise multiplication
197
+ c4 = c1 * c2
198
+
199
+ # perform homomorphic scalar multiplication
200
+ k = 5
201
+ c5 = k * c1
202
+
197
203
  # decrypt the addition tensor
198
204
  t3 = cs.decrypt(c3)
199
205
 
200
- for i, tensor in enumerate(t3):
201
- assert abs((t1[i] + t2[i]) - restored_tensor) < 0.5
206
+ # decrypt the element-wise multiplied tensor
207
+ t4 = cs.decrypt(c4)
208
+
209
+ # decrypt the scalar multiplied tensor
210
+ t5 = cs.decrypt(c5)
211
+
212
+ # data validations
213
+ threshold = 0.5
214
+ for i in range(0, len(t1)):
215
+ assert abs((t1[i] + t2[i]) - t3[i]) < threshold
216
+ assert abs((t1[i] * t2[i]) - t4[i]) < threshold
217
+ assert abs((t1[i] * k) - t5[i]) < threshold
202
218
  ```
203
219
 
220
+ Unfortunately, vector multiplication (dot product) requires both homomorphic addition and homomorphic multiplication and this cannot be done with partially homomorphic encryption algorithms.
221
+
204
222
  # Contributing
205
223
 
206
224
  All PRs are more than welcome! If you are planning to contribute a large patch, please create an issue first to get any upfront questions or design decisions out of the way first.
@@ -1,5 +1,6 @@
1
1
  LICENSE
2
2
  README.md
3
+ requirements.txt
3
4
  setup.py
4
5
  lightphe/__init__.py
5
6
  lightphe.egg-info/PKG-INFO
@@ -34,6 +35,7 @@ tests/test_cloud.py
34
35
  tests/test_damgard.py
35
36
  tests/test_elgamal.py
36
37
  tests/test_ellipticcurveelgamal.py
38
+ tests/test_exporting_keys.py
37
39
  tests/test_goldwasser.py
38
40
  tests/test_naccache.py
39
41
  tests/test_okamoto.py
@@ -0,0 +1,2 @@
1
+ sympy==1.12
2
+ pytest==7.1.2
@@ -8,10 +8,11 @@ with open("requirements.txt", "r", encoding="utf-8") as f:
8
8
 
9
9
  setuptools.setup(
10
10
  name="lightphe",
11
- version="0.0.5",
11
+ version="0.0.6",
12
12
  author="Sefik Ilkin Serengil",
13
13
  author_email="serengil@gmail.com",
14
14
  description="A Lightweight Partially Homomorphic Encryption Library for Python",
15
+ data_files=[("", ["README.md", "requirements.txt"])],
15
16
  long_description=long_description,
16
17
  long_description_content_type="text/markdown",
17
18
  url="https://github.com/serengil/LightPHE",
@@ -10,7 +10,10 @@ PUBLIC = {"public_key": {"n": 175501, "e": 101753}}
10
10
 
11
11
 
12
12
  def test_encryption():
13
- cs = LightPHE(algorithm_name="RSA", keys=PRIVATE)
13
+ # i actually have both private and public key
14
+ # but one can encrypt messages with public key only
15
+ cs = LightPHE(algorithm_name="RSA", keys=PUBLIC)
16
+ secret_cs = LightPHE(algorithm_name="RSA", keys=PRIVATE)
14
17
 
15
18
  # plaintexts
16
19
  m1 = 10000
@@ -19,15 +22,13 @@ def test_encryption():
19
22
  m2 = 1.05
20
23
  c2 = cs.encrypt(m2)
21
24
 
22
- assert cs.decrypt(c1) == m1
23
-
25
+ assert secret_cs.decrypt(c1) == m1
24
26
  logger.info("✅ Cloud encryption tests done")
25
27
 
26
28
  c3_val = homomorphic_operations(c1=c1.value, c2=c2.value)
27
29
  c3 = cs.create_ciphertext_obj(c3_val)
28
30
 
29
- assert cs.decrypt(c3) == m1 * m2
30
-
31
+ assert secret_cs.decrypt(c3) == m1 * m2
31
32
  logger.info("✅ Cloud decryption tests done")
32
33
 
33
34
 
@@ -0,0 +1,26 @@
1
+ import os
2
+ from lightphe import LightPHE
3
+ from lightphe.commons.logger import Logger
4
+
5
+ logger = Logger(module="tests/test_goldwasser.py")
6
+
7
+
8
+ # pylint: disable=eval-used
9
+ def test_private_available_after_export():
10
+ target_file = "my_public_key.lphe"
11
+ cs = LightPHE(algorithm_name="RSA")
12
+ # we are dropping private key while exporting public key
13
+ cs.export_keys(public=True, target_file=target_file)
14
+ assert cs.cs.keys.get("private_key") is not None
15
+ logger.info("✅ private key is not available in public key file as expected")
16
+
17
+ with open(target_file, "r", encoding="UTF-8") as file:
18
+ key_str = file.read()
19
+ keys = eval(key_str)
20
+ assert keys.get("private_key") is None
21
+ logger.info(
22
+ "✅ private key is available in cryptosystem's keys after"
23
+ "its public key exported as expected"
24
+ )
25
+
26
+ os.remove(target_file)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes