-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest.py
More file actions
69 lines (48 loc) · 1.39 KB
/
test.py
File metadata and controls
69 lines (48 loc) · 1.39 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
from HEAAN import *
import numpy as np
# Data support
z = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 0.1]
c = Double(z)
c.print(len(z))
b = Double(np.array(z))
b.print(len(z))
logq = 300
logp = 30
logn = 10
n = 1*2**logn
slots = n
ring = Ring()
secretKey = SecretKey(ring)
scheme = Scheme(secretKey, ring)
scheme.addLeftRotKeys(secretKey)
mevc1 = ComplexDouble()
mevc1 = EvaluatorUtils.randomComplexArray(slots)
mevc2 = ComplexDouble()
mvec2 = EvaluatorUtils.randomComplexArray(slots)
print('Plaintext1:')
StringUtils.showVec(mevc1, 2)
print('Plaintext2:')
StringUtils.showVec(mvec2, 2)
cipher1 = Ciphertext()
scheme.encrypt(cipher1, mevc1, n, logp, logq)
# SerializationUtils.writeCiphertext(cipher1, './cipher1.bin')
cipher2 = Ciphertext()
scheme.encrypt(cipher2, mvec2, n, logp, logq)
# SerializationUtils.writeCiphertext(cipher2, './cipher2.bin')
cipherAdd = Ciphertext()
scheme.add(cipherAdd, cipher1, cipher2)
cipherMult = Ciphertext()
scheme.mult(cipherMult, cipher1, cipher2)
cipherMultAfterReScale = Ciphertext()
scheme.reScaleBy(cipherMultAfterReScale, cipherMult, logp)
idx = 1
cipherRot = Ciphertext()
scheme.leftRotateFast(cipherRot, cipher1, idx)
dvec1 = ComplexDouble()
dvec2 = ComplexDouble()
dvec1 = scheme.decrypt(secretKey, cipher1)
dvec2 = scheme.decrypt(secretKey, cipher2)
print('Resultext1:')
StringUtils.showVec(dvec1, 2)
print('Resultext2:')
StringUtils.showVec(dvec2, 2)