-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLevelData.java
More file actions
67 lines (53 loc) · 2.63 KB
/
LevelData.java
File metadata and controls
67 lines (53 loc) · 2.63 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
package ckks;
import java.math.BigInteger;
import java.util.Arrays;
public class LevelData {
final static boolean debug = false;
// Product of all prime in this level
BigInteger primesProd;
// Half the above value
BigInteger halfPrimesProd;
// in [i] the product of all primes except for the i'th prime
BigInteger[] otherPrimesProds;
// in [i] the inverse of the product of all primes except for the i'th prime,
// modulo the i'th prime
BigInteger[] otherPrimesProdsInvs;
// in [i][j] product of regular primes besides the i'th regular prime, modulo
// the j'th temp prime
long[][] otherPrimesProdsMods;
// in [i] inverse of product of regular primes besides the i'th regular prime,
// modulo the i'th regular prime
long[] otherPrimesProdsInvsMod;
public LevelData(long[] primes, long[] tempPrimes, int level) {
primesProd = BigInteger.valueOf(1);
for (int primeIdx = 0; primeIdx <= level; primeIdx++)
primesProd = primesProd.multiply(BigInteger.valueOf(primes[primeIdx]));
halfPrimesProd = primesProd.divide(BigInteger.valueOf(2));
otherPrimesProds = new BigInteger[primes.length];
otherPrimesProdsInvs = new BigInteger[primes.length];
for (int primeIdx = 0; primeIdx <= level; primeIdx++) {
otherPrimesProds[primeIdx] = primesProd.divide(BigInteger.valueOf(primes[primeIdx]));
otherPrimesProdsInvs[primeIdx] = otherPrimesProds[primeIdx].mod(BigInteger.valueOf(primes[primeIdx]))
.modInverse(BigInteger.valueOf(primes[primeIdx]));
}
otherPrimesProdsMods = new long[primes.length][tempPrimes.length];
for (int tempPrimeIdx = 0; tempPrimeIdx < tempPrimes.length; tempPrimeIdx++) {
BigInteger m = BigInteger.valueOf(tempPrimes[tempPrimeIdx]);
for (int primeIdx = 0; primeIdx <= level; primeIdx++) {
otherPrimesProdsMods[primeIdx][tempPrimeIdx] = otherPrimesProds[primeIdx].mod(m).longValue();
}
}
if (debug) {
System.out.println("otherPrimesProdsMods=");
System.out.println(Arrays.deepToString(otherPrimesProdsMods) + '\n');
}
otherPrimesProdsInvsMod = new long[primes.length];
for (int primeIdx = 0; primeIdx <= level; primeIdx++)
otherPrimesProdsInvsMod[primeIdx] = otherPrimesProdsInvs[primeIdx].mod(BigInteger.valueOf(primes[primeIdx]))
.longValue();
if (debug) {
System.out.println("otherPrimesProdsInvsMod=");
System.out.println(Arrays.toString(otherPrimesProdsInvsMod) + '\n');
}
}
}