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.
- {pryvx-2.3.0 → pryvx-2.4.1}/PKG-INFO +1 -1
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx/phe.py +37 -1
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx.egg-info/PKG-INFO +1 -1
- {pryvx-2.3.0 → pryvx-2.4.1}/setup.py +1 -1
- {pryvx-2.3.0 → pryvx-2.4.1}/LICENSE +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/README.md +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx/__init__.py +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx/fl_client.py +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx/fl_server.py +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx/gdp.py +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx/pryvx_pb2.py +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx/pryvx_pb2_grpc.py +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx/psi.py +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx/smpc.py +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx.egg-info/SOURCES.txt +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx.egg-info/dependency_links.txt +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx.egg-info/requires.txt +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/pryvx.egg-info/top_level.txt +0 -0
- {pryvx-2.3.0 → pryvx-2.4.1}/setup.cfg +0 -0
@@ -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)
|
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
|
File without changes
|
File without changes
|