pryvx 2.4.0__py3-none-any.whl → 2.4.1__py3-none-any.whl
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/phe.py +24 -0
- {pryvx-2.4.0.dist-info → pryvx-2.4.1.dist-info}/METADATA +1 -1
- {pryvx-2.4.0.dist-info → pryvx-2.4.1.dist-info}/RECORD +6 -6
- {pryvx-2.4.0.dist-info → pryvx-2.4.1.dist-info}/LICENSE +0 -0
- {pryvx-2.4.0.dist-info → pryvx-2.4.1.dist-info}/WHEEL +0 -0
- {pryvx-2.4.0.dist-info → pryvx-2.4.1.dist-info}/top_level.txt +0 -0
pryvx/phe.py
CHANGED
@@ -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
|
@@ -2,13 +2,13 @@ pryvx/__init__.py,sha256=A6GcpkYgwgf_HOrneIhGs3iTsiEyvd9vYEMsmrMUqWQ,89
|
|
2
2
|
pryvx/fl_client.py,sha256=p8QPlv5-CjTCwfzN0QkPr7bjKJEbU3c9Aa3HhpvZNJE,677
|
3
3
|
pryvx/fl_server.py,sha256=9fUqZfA9RZOe0fM7FYnk_8qLNw6VMj-x8tzeGXZpgKA,890
|
4
4
|
pryvx/gdp.py,sha256=-HK3Xml-huOdfz2SSmBvpgca0iU9-RwCiaD6ZyMq7bY,408
|
5
|
-
pryvx/phe.py,sha256=
|
5
|
+
pryvx/phe.py,sha256=HN70aUNTq0w9vRPMaNGfTnNi00gMQ1B7R7Cm6r6rheE,2974
|
6
6
|
pryvx/pryvx_pb2.py,sha256=-ce40VMW0nQcjyhAJy1BvI32wtWNm425LSIExspK_qg,1200
|
7
7
|
pryvx/pryvx_pb2_grpc.py,sha256=pRQKblTNIVEwHsMQmhC-HGJFzsLh0sdOzQ-ksFYVK-A,2437
|
8
8
|
pryvx/psi.py,sha256=V0BUJwYfiFWhKtEL27q45yxY7U-I7B4olKQhaGbgN50,1346
|
9
9
|
pryvx/smpc.py,sha256=FZcE3gZo8WUVPmcBHSgP8iOkWt3AKcBLSLCtKczy8hs,2247
|
10
|
-
pryvx-2.4.
|
11
|
-
pryvx-2.4.
|
12
|
-
pryvx-2.4.
|
13
|
-
pryvx-2.4.
|
14
|
-
pryvx-2.4.
|
10
|
+
pryvx-2.4.1.dist-info/LICENSE,sha256=pbIMXbaorAIVW-fDch2tvtZRkVA3mz-UnXQqeCf4LDg,1086
|
11
|
+
pryvx-2.4.1.dist-info/METADATA,sha256=omTieHCpjPJe3yoCkJZ0SoX2sFj0IUMRfHIQB-8TUzI,1066
|
12
|
+
pryvx-2.4.1.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
13
|
+
pryvx-2.4.1.dist-info/top_level.txt,sha256=1iHoeevu_FoFjdPg8HyMlgvHNUm1--9QEpFMaJEa4hw,6
|
14
|
+
pryvx-2.4.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|