Skip to content

Commit

Permalink
python3 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cr-marcstevens committed Dec 16, 2021
1 parent bc03c2b commit caafb9f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions bkz.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def bkz_kernel(arg0, params=None, seed=None):
dont_trace = params.pop("dummy_tracer", False)

if blocksizes[-1] > d:
print 'set a smaller maximum blocksize with --blocksizes'
print('set a smaller maximum blocksize with --blocksizes')
return

challenge_seed = params.pop("challenge_seed")
Expand Down Expand Up @@ -133,9 +133,9 @@ def bkz_kernel(arg0, params=None, seed=None):
if verbose:
slope = basis_quality(M)["/"]
fmt = "{'alg': '%25s', 'jump':%2d, 'pds':%d, 'extra_d4f': %2d, 'beta': %2d, 'slope': %.5f, 'total walltime': %.3f}" # noqa
print fmt % (algbkz + "+" + ("enum" if algbkz == "fpylll" else g6k.params.default_sieve),
print( fmt % (algbkz + "+" + ("enum" if algbkz == "fpylll" else g6k.params.default_sieve),
jump, pump_params["down_sieve"], extra_dim4free,
blocksize, slope, time.time() - T0)
blocksize, slope, time.time() - T0) )

tracer.exit()
try:
Expand Down
28 changes: 14 additions & 14 deletions lwe_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def lwe_kernel(arg0, params=None, seed=None):
verbose = params.pop("verbose")

A, c, q = load_lwe_challenge(n=n, alpha=alpha)
print "-------------------------"
print "Primal attack, LWE challenge n=%d, alpha=%.4f" % (n, alpha)
print( "-------------------------" )
print( "Primal attack, LWE challenge n=%d, alpha=%.4f" % (n, alpha) )

if m is None:
try:
Expand All @@ -121,8 +121,8 @@ def lwe_kernel(arg0, params=None, seed=None):
(b, s, _) = min_cost_param
except TypeError:
raise TypeError("No winning parameters.")
print "Chose %d samples. Predict solution at bkz-%d + svp-%d" % (m, b, s)
print
print( "Chose %d samples. Predict solution at bkz-%d + svp-%d" % (m, b, s))
print("")

target_norm = goal_margin * (alpha*q)**2 * m + 1

Expand All @@ -134,7 +134,7 @@ def lwe_kernel(arg0, params=None, seed=None):
B = primal_lattice_basis(A, c, q, m=m)

g6k = Siever(B, params)
print "GSO precision: ", g6k.M.float_type
print( "GSO precision: ", g6k.M.float_type )

if dont_trace:
tracer = dummy_tracer
Expand All @@ -144,7 +144,7 @@ def lwe_kernel(arg0, params=None, seed=None):
d = g6k.full_n
g6k.lll(0, g6k.full_n)
slope = basis_quality(g6k.M)["/"]
print "Intial Slope = %.5f\n" % slope
print( "Intial Slope = %.5f\n" % slope )

T0 = time.time()
T0_BKZ = time.time()
Expand All @@ -154,7 +154,7 @@ def lwe_kernel(arg0, params=None, seed=None):

if blocksize < fpylll_crossover:
if verbose:
print "Starting a fpylll BKZ-%d tour. " % (blocksize),
print( "Starting a fpylll BKZ-%d tour. " % (blocksize), end='')
sys.stdout.flush()
bkz = BKZReduction(g6k.M)
par = fplll_bkz.Param(blocksize,
Expand All @@ -164,7 +164,7 @@ def lwe_kernel(arg0, params=None, seed=None):

else:
if verbose:
print "Starting a pnjBKZ-%d tour. " % (blocksize)
print( "Starting a pnjBKZ-%d tour. " % (blocksize) )

pump_n_jump_bkz_tour(g6k, tracer, blocksize, jump=jump,
verbose=verbose,
Expand All @@ -178,7 +178,7 @@ def lwe_kernel(arg0, params=None, seed=None):
if verbose:
slope = basis_quality(g6k.M)["/"]
fmt = "slope: %.5f, walltime: %.3f sec"
print fmt % (slope, time.time() - T0)
print( fmt % (slope, time.time() - T0) )

g6k.lll(0, g6k.full_n)

Expand All @@ -195,7 +195,7 @@ def lwe_kernel(arg0, params=None, seed=None):
if 4./3 * gaussian_heuristic(rr[d-n_expected:]) > x:
break

print "Without otf, would expect solution at pump-%d. n_max=%d in the given time." % (n_expected, n_max) # noqa
print( "Without otf, would expect solution at pump-%d. n_max=%d in the given time." % (n_expected, n_max) )# noqa
if n_expected >= n_max - 1:
continue

Expand All @@ -209,14 +209,14 @@ def lwe_kernel(arg0, params=None, seed=None):

f = d-llb-n_max
if verbose:
print "Starting svp pump_{%d, %d, %d}, n_max = %d, Tmax= %.2f sec" % (llb, d-llb, f, n_max, svp_Tmax) # noqa
print( "Starting svp pump_{%d, %d, %d}, n_max = %d, Tmax= %.2f sec" % (llb, d-llb, f, n_max, svp_Tmax) ) # noqa
pump(g6k, tracer, llb, d-llb, f, verbose=verbose,
goal_r0=target_norm * (d - llb)/(1.*d))

if verbose:
slope = basis_quality(g6k.M)["/"]
fmt = "\n slope: %.5f, walltime: %.3f sec"
print fmt % (slope, time.time() - T0)
print( fmt % (slope, time.time() - T0) )
print

g6k.lll(0, g6k.full_n)
Expand All @@ -225,8 +225,8 @@ def lwe_kernel(arg0, params=None, seed=None):
break

if g6k.M.get_r(0, 0) <= target_norm:
print "Finished! TT=%.2f sec" % (time.time() - T0)
print g6k.M.B[0]
print( "Finished! TT=%.2f sec" % (time.time() - T0) )
print( g6k.M.B[0] )
alpha_ = int(alpha*1000)
filename = 'lwechallenge/%03d-%03d-solution.txt' % (n, alpha_)
fn = open(filename, "w")
Expand Down
2 changes: 1 addition & 1 deletion quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def asvp_kernel(arg0, params=None, seed=None):

stat.data["quality"] = quality

print >> sys.stderr, g6k.M.B
print( g6k.M.B, file=sys.stderr )

return tracer.trace

Expand Down
4 changes: 2 additions & 2 deletions svp_exact_find_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def svp_kernel(arg0, params=None, seed=None):
else:
matches = 0
goal_r0 = found_r0
print "\t", (n, challenge_seed), "Trial %3d, found norm %10d = %.4f*gh, consec matches %d/5" % (
trials, goal_r0, goal_r0/gh, matches)
print("\t", (n, challenge_seed), "Trial %3d, found norm %10d = %.4f*gh, consec matches %d/5" % (
trials, goal_r0, goal_r0/gh, matches))

save_svpchallenge_norm(n, goal_r0, s=challenge_seed)

Expand Down

0 comments on commit caafb9f

Please sign in to comment.