-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_estimator.py
More file actions
60 lines (55 loc) · 2.41 KB
/
test_estimator.py
File metadata and controls
60 lines (55 loc) · 2.41 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
from latticeestimator.estimator import *
from latticeestimator.estimator.nd import NoiseDistribution
from latticeestimator.estimator.lwe_parameters import LWEParameters
from math import log2
def run_estimator_hybrid():
nlogs = [14, 15, 16, 17]
hs = [128, 256, 512]
logqs = [700,750,800,850,900,950,1000]
res = []
for nlog in nlogs:
for h in hs:
for logq in logqs:
FHEParam = LWEParameters(
n =2**nlog,
q= 2**logq,
Xs=ND.SparseTernary(p = h/2, m=h/2, n=2**nlog),
Xe=ND.DiscreteGaussian(stddev=3.19)
)
try:
primal_hybrid_cost = LWE.primal_hybrid(FHEParam, red_cost_model=RC.BDGL16, mitm=False)
#print(primal_hybrid_cost)
ll = log2(primal_hybrid_cost['rop'])
beta = primal_hybrid_cost['beta']
eta = primal_hybrid_cost['eta']
zeta = primal_hybrid_cost['zeta']
d = primal_hybrid_cost['d']
svp_cost = log2(float(primal_hybrid_cost["svp"]))
red_cost = log2(float(primal_hybrid_cost["red"]))
prob = primal_hybrid_cost["prob"]
#[logq, h, beta, ng, d, wg, lambda]
res.append([nlog, h, beta, zeta, d, round(ll)])
print(f"n:{nlog} logq:{logq } h:{h} eta: {eta} beta:{beta} lambda:{ll} zeta:{zeta} d:{d} red:{red_cost} svp:{svp_cost} prob:{prob} ")
print("------------------------------")
except Exception as e:
print('error in the estimator:', e)
print("------------------------------")
print(res)
def run_estimator():
nlogs = [14, 15, 16]
logqs = [700, 750, 800, 850, 900, 950, 1000]
for nlog in nlogs:
for logq in logqs:
FHEParam = LWEParameters(
n =2**nlog,
q= 2**logq,
Xs=ND.UniformMod(2),
Xe=ND.DiscreteGaussian(stddev=3.19),
)
primal_uSVP_cost = LWE.primal_usvp(FHEParam, red_cost_model=RC.BDGL16)
print(primal_uSVP_cost)
primal_hybrid_cost_bdd = LWE.bdd(FHEParam, red_cost_model=RC.BDGL16)
print(primal_hybrid_cost_bdd)
if __name__ == "__main__":
#run_estimator()
run_estimator_hybrid()