-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDecryptor.java
More file actions
33 lines (24 loc) · 800 Bytes
/
Decryptor.java
File metadata and controls
33 lines (24 loc) · 800 Bytes
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
package ckks;
public class Decryptor {
private SecretKey secretKey;
public Decryptor(SecretKey secretKey) {
this.secretKey = secretKey;
}
public void decrypt(Ciphertext src, Plaintext res) {
if (src.isEmpty())
throw new IllegalArgumentException("Ciphertext is empty.");
Polynomial s = secretKey.getS();
Polynomial m;
if (src.isLinear()) {
Polynomial b = src.getB();
Polynomial a = src.getA();
m = b.add(a.mult(s));
} else {
Polynomial d0 = src.getD0();
Polynomial d1 = src.getD1();
Polynomial d2 = src.getD2();
m = d0.add(d1.mult(s)).add(d2.mult(s.square()));
}
res.init(m, src.getScale(), src.getLevel());
}
}