pryvx 2.3.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.3.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,9 +64,37 @@ 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
62
86
  n2 = n * n
63
87
  c2_inv = mod_inverse(c2, n2)
64
- return (c1 * c2_inv) % n2
88
+ return (c1 * c2_inv) % n2
89
+
90
+ @staticmethod
91
+ def homomorphic_scalar_mult(ciphertext, scalar, public_key):
92
+ n, g = public_key
93
+ n2 = n * n
94
+ return pow(ciphertext, scalar, n2)
95
+
96
+ @staticmethod
97
+ def homomorphic_div(ciphertext, divisor, public_key):
98
+ n, g = public_key
99
+ divisor_inv = mod_inverse(divisor, n) # Find the modular inverse of the divisor modulo n
100
+ return PHE.homomorphic_scalar_mult(ciphertext, divisor_inv, public_key)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pryvx
3
- Version: 2.3.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.3.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