Commit 481e810f authored by MASSON Simon's avatar MASSON Simon
Browse files

conflicts?

parents d770bd15 2a7e28ec
import sage
from exceptions import ValueError
try:
from exceptions import ValueError
except ModuleNotFoundError:
pass
from sage.functions.log import log
from sage.functions.other import ceil
from sage.arith.misc import XGCD, xgcd
......
import sage
from exceptions import ValueError
try:
from exceptions import ValueError
except ModuleNotFoundError:
pass
from sage.functions.log import log
from sage.functions.other import ceil
from sage.arith.misc import XGCD, xgcd
......
......@@ -6,7 +6,10 @@
import sage
from exceptions import ValueError
try:
from exceptions import ValueError
except ModuleNotFoundError:
pass
from sage.functions.log import log
from sage.functions.other import ceil
from sage.arith.misc import XGCD, xgcd
......
......@@ -2,7 +2,10 @@
# j = 0
import sage
from exceptions import ValueError
try:
from exceptions import ValueError
except ModuleNotFoundError:
pass
from sage.functions.log import log
from sage.functions.other import ceil
from sage.functions.other import sqrt
......
......@@ -2,7 +2,10 @@
# j = 1728
import sage
from exceptions import ValueError
try:
from exceptions import ValueError
except ModuleNotFoundError:
pass
from sage.functions.log import log
from sage.functions.other import ceil
from sage.functions.other import sqrt
......
......@@ -5,6 +5,12 @@ from sage.rings.factorint import factor_trial_division
import sage.rings.integer
from enumerate_sparse_T import *
import itertools
try:
from itertools import imap
except ImportError:
# Python 3
imap=map
from collections import defaultdict
import re
import pprint
......@@ -24,7 +30,7 @@ seed=0
# utilities
def md5int(T):
return Integer(md5(str(T)).hexdigest(), 16)
return Integer(md5(str(T).encode('utf-8')).hexdigest(), 16)
def get_prod_pi(k):
"""
......@@ -362,7 +368,7 @@ def attempt_to_factor(n, known=[], max_trialdiv=10**6, max_B1=10**4):
except KeyboardInterrupt:
raise
except:
print "ECM failed on %d" % n
print("ECM failed on {}".format(n))
raise
for p in fn:
L[p]+=1
......@@ -624,7 +630,7 @@ class CocksPinchVariantResult(object):
self._twist_E2 = None
if pre:
print "C=%s" % repr(self)
print("C={}".format(repr(self)))
def u(self):
return self.T
......@@ -764,7 +770,7 @@ class CocksPinchVariantResult(object):
def _factor_and_return(self, tt, factor=False):
if not factor:
return tt
if tt.has_key("factorization"):
if "factorization" in tt:
if tt["max_B1"] >= self.max_B1 or not tt["factorization"][1]:
return tt
tt["max_B1"] = self.max_B1
......@@ -1101,7 +1107,7 @@ class CocksPinchVariantSearch(object):
self.restrict_i = restrict_i
self.parallel = { 'T': None, 'ht': None, 'hy':None }
if parallel:
assert self.parallel.has_key(parallel[0])
assert parallel[0] in self.parallel
self.parallel[parallel[0]] = parallel[1:3]
self.seed = seed
self.statefile = statefile
......@@ -1141,7 +1147,7 @@ class CocksPinchVariantSearch(object):
else:
print("# results written in file %s " % self.output_file)
if self.out_file:
print >>self.out_file, "# START [T:%s ; hty:%s] %s" % (self.T_choice, self.hty_choice, time.asctime())
print("# START [T:{} ; hty:{}] {}".format(self.T_choice, self.hty_choice, time.asctime()), file=self.out_file)
self.out_file.flush()
class range_class_on_T(object):
......@@ -1162,8 +1168,7 @@ class CocksPinchVariantSearch(object):
self.Tmin = ceil((self.phi - 2**(lambdar-1)).roots(RR)[-1][0])
self.Tmax = ceil((self.phi - 2**(lambdar)).roots(RR)[-1][0])
print "Explore T range %d .. %d [%s]" % (self.Tmin,
self.Tmax, self.search_parent.T_choice)
print("Explore T range {} .. {} [{}]".format(self.Tmin, self.Tmax, self.search_parent.T_choice))
self.raw_Trange = range_with_strategy(
self.Tmin, self.Tmax,
......@@ -1455,7 +1460,7 @@ class CocksPinchVariantSearch(object):
tc = ",".join([et] + ht_only_tokens)
th = ",".join([eh] + hy_only_tokens)
all_hty_choices.append((tc, th))
print "Will enumerate cofactors ht and hy based on the following schedule:"
print("Will enumerate cofactors ht and hy based on the following schedule:")
for ht_choice, hy_choice in all_hty_choices:
pt = ht_choice
if not pt:
......@@ -1469,7 +1474,7 @@ class CocksPinchVariantSearch(object):
if self.search_parent.parallel['hy']:
i,n = self.search_parent.parallel['hy']
py += ", split %d/%d" % (i,n)
print "\t%s and %s" % (pt, py)
print("\t{} and {}".format(pt, py))
self.all_hty_choices = sequence_with_stateful_iterators(all_hty_choices)
def __iter__(self):
......@@ -1547,7 +1552,7 @@ class CocksPinchVariantSearch(object):
self.current = []
self.it = [ iter(r) for r in self.range_parent.ranges[:len(s)]]
for i,ss in enumerate(s):
print "Resetting iterator %d with state %s" % (i, ss)
print("Resetting iterator {} with state {}".fornat(i, ss))
self.it[i].setstate(ss)
# If previous_state was correctly implemented on all
# sub-iterators, then we will not get a StopIteration
......@@ -1598,7 +1603,7 @@ class CocksPinchVariantSearch(object):
with open(self.statefile, "r") as f:
state = pickle.load(f)
it.setstate(state)
print "Restored state from %s: %s" % (self.statefile, state)
print("Restored state from {}: {}".format(self.statefile, state))
except IOError:
pass
except EOFError:
......@@ -1609,24 +1614,24 @@ class CocksPinchVariantSearch(object):
with open(self.statefile, "w") as f:
pickle.dump(oldstate, f)
if self.verbose:
print "Saved state to %s: %s" % (self.statefile, oldstate)
print("Saved state to {}: {}".format(self.statefile, oldstate))
try:
self.subloop()
except KeyboardInterrupt:
print "Interrupted"
print("Interrupted")
return
# ss = it.previous_state
# it.setstate(ss)
# bar = next(it)
# assert foo == bar
print "DONE [T:%s ; hty:%s] %s" % (self.T_choice, self.hty_choice, time.asctime())
print "generated %d good curves among %d candidate curves in %f s" % (self.ng, self.nc, time.time() - self.time0)
print("DONE [T:{} ; hty:{}] {}".format(self.T_choice, self.hty_choice, time.asctime()))
print("generated {} good curves among {} candidate curves in {} s".format(self.ng, self.nc, time.time() - self.time0))
pprint.pprint(dict(self.fail))
if self.out_file:
print >>self.out_file, "# DONE [T:%s ; hty:%s] %s" % (self.T_choice, self.hty_choice, time.asctime())
print >>self.out_file, "# generated %d good curves among %d candidate curves in %f s" % (self.ng, self.nc, time.time() - self.time0)
print >>self.out_file, re.sub("^","# ",pprint.pformat(dict(self.fail)), re.MULTILINE) + "\n"
print("# DONE [T:{} ; hty:{}] {}".format(self.T_choice, self.hty_choice, time.asctime()), file=self.out_file)
print("# generated {} good curves among {} candidate curves in {} s".format(self.ng, self.nc, time.time() - self.time0), file=self.out_file)
print(re.sub("^","# ",pprint.pformat(dict(self.fail)), re.MULTILINE) + "\n", file=self.out_file)
self.out_file.flush()
self.out_file.close()
......@@ -1653,7 +1658,7 @@ class CocksPinchVariantSearch(object):
# True means: keep checking.
return True
print "Gcd of the curve orders after 16 curves generated [allowed_automatic_cofactor=%d, allowed_cofactor=%d, allowed_size_cofactor=%d, required_cofactor=%d]:" % (self.allowed_automatic_cofactor, self.allowed_cofactor, self.allowed_size_cofactor, self.required_cofactor)
print("Gcd of the curve orders after 16 curves generated [allowed_automatic_cofactor={}, allowed_cofactor={}, allowed_size_cofactor={}, required_cofactor={}]:".format(self.allowed_automatic_cofactor, self.allowed_cofactor, self.allowed_size_cofactor, self.required_cofactor))
pprint.pprint(dict(g))
# Time for a final check.
......@@ -1669,10 +1674,10 @@ class CocksPinchVariantSearch(object):
# be filtered to produce curves that are valid for all cases.
for kk in ['E', 'E2', 'Et', 'E2t', 'all']:
if gcd(g[kk], self.allowed_automatic_cofactor) != g[kk]:
print "#########################################"
print "## Aborting this search, as we have non-trivial algebraic factors on the curves that are larger than allowed_automatic_cofactor (%d):" % self.allowed_automatic_cofactor
print("#########################################")
print("## Aborting this search, as we have non-trivial algebraic factors on the curves that are larger than allowed_automatic_cofactor ({}):".format(self.allowed_automatic_cofactor))
pprint.pprint(dict(g))
print "#########################################"
print("#########################################")
return False
return True
......@@ -1715,7 +1720,7 @@ class CocksPinchVariantSearch(object):
pre_hy_choice = self.pre_hy_choice
fail = self.fail
print "T=%s i=%d # Explore pre_ht range is (raw) %d .. %d [%s]" % (phex(T), i, pre_htmin, pre_htmax, pre_ht_choice)
print("T={} i={} # Explore pre_ht range is (raw) {} .. {} [{}]".format(phex(T), i, pre_htmin, pre_htmax, pre_ht_choice))
pre_htgen = itertools.chain(
chain_alternate_iterators(
......@@ -1724,7 +1729,7 @@ class CocksPinchVariantSearch(object):
strategy=pre_ht_choice,
split=self.parallel['ht'],
random_state=self.random_state),
itertools.imap(lambda x:-x,
imap(lambda x:-x,
range_with_strategy(
Integer(1), 1-self.pre_htmin,
strategy=pre_ht_choice,
......@@ -1865,7 +1870,7 @@ class CocksPinchVariantSearch(object):
strategy=pre_hy_choice,
split=self.parallel['hy'],
random_state=self.random_state)
ii1 = itertools.imap(lambda x:-x, ii1)
ii1 = imap(lambda x:-x, ii1)
pre_hygen = itertools.chain(ii0, ii1)
else:
# Then we must do something special
......@@ -1882,7 +1887,7 @@ class CocksPinchVariantSearch(object):
strategy=hc,
split=self.parallel['hy'],
random_state=self.random_state)
ii1 = itertools.imap(lambda x:-x, ii1)
ii1 = imap(lambda x:-x, ii1)
pre_hygen = itertools.chain(pre_hygen, ii0, ii1)
# }}}
if pre_hysize == 0:
......@@ -1895,7 +1900,7 @@ class CocksPinchVariantSearch(object):
old_range_text = range_text
range_text = " # Explore hy range %s [%s]" % (range_text, pre_hy_choice)
print "\tT=0x%s, -D=%d, i=%d, ht=%d%s" % (T.hex(), -fD, i, ht, range_text)
print("\tT=0x{}, -D={}, i={}, ht={}{}".format(T.hex(), -fD, i, ht, range_text))
# print "Looking at %d congruence classes among %d" % (len(cmodk_set), kq)
# arrange to print only rarely
......@@ -1995,7 +2000,7 @@ class CocksPinchVariantSearch(object):
self.nc += 1
if self.nc % 65536 == 0:
print "generated %d candidate curves in %f s" % (self.nc, time.time() - self.time0)
print("generated {} candidate curves in {} s".format(self.nc, time.time() - self.time0))
pprint.pprint(dict(fail))
sys.stdout.flush()
......@@ -2035,14 +2040,14 @@ class CocksPinchVariantSearch(object):
# continue
self.ng += 1
print E
print(E)
if self.out_file:
print >>self.out_file, E
print(E, file=self.out_file)
self.out_file.flush()
except KeyboardInterrupt:
raise
except:
print "Problem with %s" % repr(E)
print("Problem with %s".format(repr(E)))
raise
if self.out_file:
# print >>self.out_file
......
......@@ -3,7 +3,10 @@
# any j possible
import sage
from exceptions import ValueError
try:
from exceptions import ValueError
except ModuleNotFoundError:
pass
from sage.functions.log import log
from sage.functions.other import ceil
from sage.functions.other import sqrt
......
......@@ -33,7 +33,10 @@ LAMBx_den = 1
import sage
from exceptions import ValueError
try:
from exceptions import ValueError
except ModuleNotFoundError:
pass
from sage.functions.log import log
from sage.functions.other import ceil
from sage.functions.other import sqrt
......
import sage
from exceptions import ValueError
try:
from exceptions import ValueError
except ModuleNotFoundError:
pass
from sage.functions.log import log
from sage.functions.other import ceil
from sage.arith.misc import XGCD, xgcd
......
......@@ -2,7 +2,10 @@
# This time, j != 0.
import sage
from exceptions import ValueError
try:
from exceptions import ValueError
except ModuleNotFoundError:
pass
from sage.functions.log import log
from sage.functions.other import ceil
from sage.functions.other import sqrt
......
import sage
from exceptions import ValueError
try:
from exceptions import ValueError
except ModuleNotFoundError:
pass
from sage.functions.log import log
from sage.functions.other import ceil
from sage.arith.functions import lcm
......@@ -496,6 +499,6 @@ def print_JL_polys(C,Y):
for gi in g[:-1]:
str_gx += "{:#x},".format(gi)
str_gx += "{:#x}],".format(g[-1])
print str_f
print str_gx
print str_g
print(str_f)
print(str_gx)
print(str_g)
......@@ -28,10 +28,10 @@ class TestPairingFriendlyCurve():
try:
Ei_a = self._PFCurve(u=u, ht=ht, hy=hy, exp_tr=exp_tr, p=p, r=r, c=c, tr=tr, y=y, a=a)
except ValueError as err:
print ("Error init(u={},a={},ht={},hy={},exp_tr={}\np={}\nr={}\nc={}\ntr={}\ny={}\n)".format(u,a,ht,hy,exp_tr,p,r,c,tr,y))
print("Error init(u={},a={},ht={},hy={},exp_tr={}\np={}\nr={}\nc={}\ntr={}\ny={}\n)".format(u,a,ht,hy,exp_tr,p,r,c,tr,y))
print("{}".format(err))
raise
print Ei_a
print(Ei_a)
self._Ei_a.append(Ei_a)
print("OK")
return True
......@@ -44,10 +44,10 @@ class TestPairingFriendlyCurve():
try:
Ei_b = self._PFCurve(u=u, ht=ht, hy=hy, exp_tr=exp_tr, p=p, r=r, c=c, tr=tr, y=y, b=b)
except ValueError as err:
print ("Error init(u={},b={},ht={},hy={},exp_tr={}\np={}\nr={}\nc={}\ntr={}\ny={}\n)".format(u,b,ht,hy,exp_tr,p,r,c,tr,y))
print("Error init(u={},b={},ht={},hy={},exp_tr={}\np={}\nr={}\nc={}\ntr={}\ny={}\n)".format(u,b,ht,hy,exp_tr,p,r,c,tr,y))
print("{}".format(err))
raise
print Ei_b
print(Ei_b)
self._Ei_b.append(Ei_b)
print("OK")
return True
......@@ -60,10 +60,10 @@ class TestPairingFriendlyCurve():
try:
Ei_ab = self._PFCurve(u, a=a, b=b, c=c, D=D)
except ValueError as err:
print ("Error init({},a={},b={},c={},D={})".format(u,a,b,c,D))
print("Error init({},a={},b={},c={},D={})".format(u,a,b,c,D))
print("{}".format(err))
raise
print Ei_ab
print(Ei_ab)
self._Ei_ab.append(Ei_ab)
print("OK")
return True
......@@ -76,10 +76,10 @@ class TestPairingFriendlyCurve():
try:
Ei_ab = self._PFCurve(k,u,D,exp_tr,p,r,tr,y,a,b)
except ValueError as err:
print ("Error init(k={},T={},D={},i={},a={},b={})".format(k,u,D,exp_tr,a,b))
print("Error init(k={},T={},D={},i={},a={},b={})".format(k,u,D,exp_tr,a,b))
print("{}".format(err))
raise
print Ei_ab
print(Ei_ab)
self._Ei_ab.append(Ei_ab)
print("OK")
return True
......@@ -92,10 +92,10 @@ class TestPairingFriendlyCurve():
try:
Ei_b = self._PFCurve(u, b=b)
except ValueError as err:
print ("Error init({},b={})".format(u,b))
print("Error init({},b={})".format(u,b))
print("{}".format(err))
raise
print Ei_b
print(Ei_b)
self._Ei_b.append(Ei_b)
print("OK")
return True
......@@ -108,10 +108,10 @@ class TestPairingFriendlyCurve():
try:
Ei_a = self._PFCurve(u, a=a)
except ValueError as err:
print ("Error init({},a={})".format(u,a))
print("Error init({},a={})".format(u,a))
print("{}".format(err))
raise
print Ei_a
print(Ei_a)
self._Ei_a.append(Ei_a)
print("OK")
return True
......@@ -124,10 +124,10 @@ class TestPairingFriendlyCurve():
try:
Ei = self._PFCurve(u)
except ValueError as err:
print ("Error init ({})".format(u))
print("Error init ({})".format(u))
print("{}".format(err))
raise
print Ei
print(Ei)
self._Ei.append(Ei)
print("OK")
return True
......@@ -138,16 +138,16 @@ class TestPairingFriendlyCurve():
if not r.is_prime():
print("Error r is not prime")
if not r*G == E(0):
print ("Error generator G is not of order r, r*G = {}".format(r*G))
print("Error generator G is not of order r, r*G = {}".format(r*G))
beta = E.beta()
sigmaG = E(G[0]*beta, G[1])
sigma2G = E(sigmaG[0]*beta, sigmaG[1])
if r*sigmaG != E(0):
print ("Error r*sigma(G) != 0, obtained: {}".format(r*sigmaG))
print("Error r*sigma(G) != 0, obtained: {}".format(r*sigmaG))
if r*sigma2G != E(0):
print ("Error r*sigma^2(G) != 0, obtained: {}".format(r*sigma2G))
print("Error r*sigma^2(G) != 0, obtained: {}".format(r*sigma2G))
if sigma2G + sigmaG + G != E(0):
print ("Error sigma^2(G) + sigma(G) + G != 0, obtained: {}".format(sigma2G + sigmaG + G))
print("Error sigma^2(G) + sigma(G) + G != 0, obtained: {}".format(sigma2G + sigmaG + G))
lamb = E.lamb()
if lamb*G != sigmaG:
print("Error lamb*G != sigma(G)")
......@@ -157,11 +157,11 @@ class TestPairingFriendlyCurve():
def test_beta_lamb_sigma_j0(self):
print("test_beta_lamb_sigma_j0")
for Ei in self._Ei:
#print Ei
#print(Ei)
self._test_beta_lamb_sigma_j0(Ei)
print("")
for Ei_b in self._Ei_b:
#print Ei_b
#print(Ei_b)
self._test_beta_lamb_sigma_j0(Ei_b)
print("OK")
return True
......@@ -172,16 +172,16 @@ class TestPairingFriendlyCurve():
if not r.is_prime():
print("Error r is not prime")
if not r*G == E(0):
print ("Error generator G is not of order r, r*G = {}".format(r*G))
print("Error generator G is not of order r, r*G = {}".format(r*G))
beta = E.beta()
sigmaG = E(-G[0], G[1]*beta)
sigma2G = E(-sigmaG[0], sigmaG[1]*beta)
if r*sigmaG != E(0):
print ("Error r*sigma(G) != 0, obtained: {}".format(r*sigmaG))
print("Error r*sigma(G) != 0, obtained: {}".format(r*sigmaG))
if r*sigma2G != E(0):
print ("Error r*sigma^2(G) != 0, obtained: {}".format(r*sigma2G))
print("Error r*sigma^2(G) != 0, obtained: {}".format(r*sigma2G))
if sigma2G + G != E(0):
print ("Error sigma^2(G) + G != 0, obtained: {}".format(sigma2G + G))
print("Error sigma^2(G) + G != 0, obtained: {}".format(sigma2G + G))
lamb = E.lamb()
if lamb*G != sigmaG:
print("Error lamb*G != sigma(G)")
......@@ -191,11 +191,11 @@ class TestPairingFriendlyCurve():
def test_beta_lamb_sigma_j1728(self):
print("test_beta_lamb_sigma_j1728")
for Ei in self._Ei:
#print Ei
#print(Ei)
self._test_beta_lamb_sigma_j1728(Ei)
print("")
for Ei_a in self._Ei_a:
#print Ei_a
#print(Ei_a)
self._test_beta_lamb_sigma_j1728(Ei_a)
print("OK")
return True
......@@ -203,19 +203,19 @@ class TestPairingFriendlyCurve():
def test_print_parameters(self):
print("test_print_parameters")
for Ei in self._Ei:
print Ei
print(Ei)
Ei.print_parameters()
Ei.print_parameters_for_RELIC()
for Ei_ab in self._Ei_ab: # list may is empty
print Ei_ab
print(Ei_ab)
Ei_ab.print_parameters()
Ei_ab.print_parameters_for_RELIC()
for Ei_a in self._Ei_a: # list is empty if j != 1728
print Ei_a
print(Ei_a)
Ei_a.print_parameters()
Ei_a.print_parameters_for_RELIC()
for Ei_b in self._Ei_b: # list is empty if j != 0
print Ei_b
print(Ei_b)
Ei_b.print_parameters()
Ei_b.print_parameters_for_RELIC()
......@@ -290,7 +290,7 @@ def generate_parameters_high(pnbits, poly_p, poly_r, polys_cofact_twist=[], u_mo
cond = cond or not ci.is_pseudoprime()
i +=1
if verbose and (i % 10**5) == 0:
print i
print(i)
print("gcd all p: {} gcd all r: {} gcd all ci: {}".format(gcd_p, gcd_r, gcd_ci))
# reset
gcd_p = 0
......
......@@ -32,17 +32,20 @@ def cost_m(k) :
return 22*m
else :
return 'not done for this embedding degree'
# special cases
def densexsparse_m6(k):
# Aurore thesis, when half of the coefficients of one element are zero in Fpk defined over Fpk/6
assert k%6==0
return 13*cost_m(k//6) # aurore thesis
return 13*cost_m(k//6)
#SIMON
SIMON = True
def densexsparse_m8(k):
# when half of the coefficients of one element is zero in Fpk defined over Fpk/4
assert k%8==0
return 8*cost_m(k//4) # ??????????????????????BarDuq18???
return 8*cost_m(k//4)
sparse_m12 = 13*cost_m(2) # BarDuq 39 = 3*13 and 3 is the cost of Mp2 = 3 Mp
sparse_m16 = 8*cost_m(4)
......@@ -62,8 +65,17 @@ def cost_s(k) :
else :
return 'not done for this embedding degree'
# special cases
cyclo_s6 = 3*cost_s(2) # eprint 2009/565
cyclo_s8 = 2*cost_s(4) # eprint 2009/565 section 3.1
def cost_s_cyclo(k) :
# return the cost of a cyclotomic square over F_{p^k}
if k%6 == 0 :
return 3*cost_s(k//3)
elif k%2 == 0 :
return 2*cost_s(k//2)
else :
return 'not done for this embedding degree'
cyclo_s6 = 3*cost_s(2) # eprint(2009/565)
cyclo_s8 = 2*cost_s(4) # eprint(2009/565) section 3.1
compr_s12 = 12*m # BarDuq
cyclo_s12 = 18*m
cyclo_s16 = 2*cost_s(8)
......@@ -178,11 +190,11 @@ def table_costFpk(k_list):
r"\hline",
r"\end{array}$$",
]
print "% This table is generated by:"
print "%% PYTHONPATH=cocks-pinch-variant/ sage -c 'load(\"cocks-pinch-variant/cost_pairing.py\"); table_costFpk(%s)'" % (k_list)
print("% This table is generated by:")
print("%% PYTHONPATH=cocks-pinch-variant/ sage -c 'load(\"cocks-pinch-variant/cost_pairing.py\"); table_costFpk(%s)'" % (k_list))