-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBFV_demo.py
More file actions
73 lines (54 loc) · 1.55 KB
/
Copy pathBFV_demo.py
File metadata and controls
73 lines (54 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from BFV import *
# Determine n and bit-size of q, then find a
# q satisfying the condition: q = 1 (mod 2n)
#
# Based on n and q, generate NTT parameters
n = 0
q = 0
psi = 0
# Determine t
t = 1024
print("--- Starting BFV (SEAL) Demo")
n = 4096
#RNS base q
q = [68719403009, 68719230977, 137438822401]
k = len(q)
q_psi = [24250113, 29008497, 8625844]
# RNS base b = 2 tane rastgele mod sonuncusu m_sk
b = [2305843009213317121, 2305843009213243393, 2305843009213145089]
l = len(b)
b_psi = [829315415491244, 32973993658837, 307554654119321]
# Determine B (bound of distribution X)
sigma = 3.2
# Determine T, p (relinearization)
T = 256
p = 16
# RNS BFV Evaluator
Evaluator = BFV(n, t, q, b, q_psi, b_psi)
# Generate Keys
Evaluator.SecretKeyGen()
Evaluator.PublicKeyGen()
# print secret and public keys
print("--- Secret and Public Key are generated.")
print("* sk: {}".format(Evaluator.sk))
print("* pk[0]: {}".format(Evaluator.pk[0]))
print("* pk[1]: {}".format(Evaluator.pk[1]))
print("")
# print system parameters
print(Evaluator)
# Generate random message
m = 100
# Encode random messages into plaintext polynomials
m_plain, m_len = Evaluator.EncodeInt(m)
# Encrypt message
ct1 = Evaluator.EncryptionSEAL_RNS(m_plain, m_len)
mt = Evaluator.DecryptionSEAL_RNS(ct1)
# Decode decrypted polynomial into integer
nr = Evaluator.DecodeInt(mt, m_len)
if (m_plain == mt) and (nr == m):
print("--- Encryption-Decryption works.")
else:
print("--- Encryption-Decryption does not work.")
# Homomorphic Operations
# Evaluator.HomomorphicMultiplication_RNS(ct1, ct1)
#