pryvx 2.4.0__tar.gz → 2.4.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pryvx
3
- Version: 2.4.0
3
+ Version: 2.4.1
4
4
  Summary: A comprehensive package for privacy-enhancing technologies
5
5
  Home-page: UNKNOWN
6
6
  Author: PryvX (Jayesh Kenaudekar)
@@ -26,6 +26,14 @@ class PHE:
26
26
  private_key = (lambda_n, mu)
27
27
  return public_key, private_key
28
28
 
29
+ @staticmethod
30
+ def encode(value, scale_factor=1000):
31
+ return int(round(value * scale_factor))
32
+
33
+ @staticmethod
34
+ def decode(value, scale_factor=1000):
35
+ return value / scale_factor
36
+
29
37
  @staticmethod
30
38
  def encrypt(public_key, plaintext, r=None):
31
39
  n, g = public_key
@@ -56,6 +64,22 @@ class PHE:
56
64
  n2 = n * n
57
65
  return (c1 * c2) % n2
58
66
 
67
+ @staticmethod
68
+ def homomorphic_add_plaintext(ciphertext, plaintext, public_key):
69
+ n, g = public_key
70
+ n2 = n * n
71
+ c_plain = pow(g, plaintext, n2)
72
+ return (ciphertext * c_plain) % n2
73
+
74
+ @staticmethod
75
+ def homomorphic_sub_plaintext(ciphertext, plaintext, public_key):
76
+ n, g = public_key
77
+ n2 = n * n
78
+
79
+ # Encrypt the plaintext as its negative (-plaintext) mod n
80
+ c_plain_neg = pow(g, -plaintext % n, n2) # Modular inverse for subtraction
81
+ return (ciphertext * c_plain_neg) % n2
82
+
59
83
  @staticmethod
60
84
  def homomorphic_sub(c1, c2, public_key):
61
85
  n, _ = public_key
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pryvx
3
- Version: 2.4.0
3
+ Version: 2.4.1
4
4
  Summary: A comprehensive package for privacy-enhancing technologies
5
5
  Home-page: UNKNOWN
6
6
  Author: PryvX (Jayesh Kenaudekar)
@@ -1,6 +1,6 @@
1
1
  from setuptools import setup, find_packages
2
2
 
3
- VERSION = '2.4.0'
3
+ VERSION = '2.4.1'
4
4
 
5
5
 
6
6
  # Setting up
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
File without changes
File without changes
File without changes