-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEncryptor.java
More file actions
48 lines (39 loc) · 1.34 KB
/
Encryptor.java
File metadata and controls
48 lines (39 loc) · 1.34 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
package ckks;
public class Encryptor {
final boolean debug = false;
private Context context;
PublicKeys publicKey;
public Encryptor(Context context, PublicKeys publicKey) {
this.context = context;
this.publicKey = publicKey;
}
public void encrypt(Plaintext src, Ciphertext res) {
Polynomial v = KeyGenerator.ternaryDist(context, 0.5);
Polynomial e1 = KeyGenerator.ternaryDist(context, 0.5);
Polynomial e2 = KeyGenerator.ternaryDist(context, 0.5);
if (debug) {
System.out.println("Encryptor.encrypt");
System.out.println("v");
v.debugPrint();
System.out.println("");
System.out.println("e1");
e1.debugPrint();
System.out.println("");
System.out.println("e2");
e2.debugPrint();
}
Polynomial m = src.getM();
Polynomial bKey = publicKey.getB();
Polynomial aKey = publicKey.getA();
Polynomial b = v.mult(bKey).add(m).add(e1);
Polynomial a = v.mult(aKey).add(e2);
if (debug) {
System.out.println("final b");
b.debugPrint();
System.out.println("");
System.out.println("final a");
a.debugPrint();
}
res.init(b, a, src.getLevel(), src.getScale());
}
}