def main(n=150, block_size=60, float_type="d", logq=40, verbose=False, seed=0xdeadbeef): print "= n: %3d, β: %2d, bits: %3d, float_type: %s, seed: 0x%08x =" % ( n, block_size, logq, float_type, seed) print set_random_seed(seed) A = IntegerMatrix.random(n, "qary", k=n // 2, bits=logq) A = LLL.reduction(A) params = BKZ.Param(block_size=block_size, max_loops=4, strategies=BKZ.DEFAULT_STRATEGY, flags=BKZ.MAX_LOOPS | BKZ.VERBOSE) bkz = BKZReduction(GSO.Mat(copy.copy(A), float_type=float_type)) bkz(params) print bkz.trace bkz2 = BKZ2(GSO.Mat(copy.copy(A), float_type=float_type)) bkz2(params) print bkz2.trace if verbose: print print bkz.trace.report()
def test_bkz_init(): for cls in (SimpleBKZ, SimpleDualBKZ, BKZ, BKZ2): for n in dimensions: set_random_seed(2 ** 10 + n) A = make_integer_matrix(n) B = cls(copy(A)) del B
def test_bkz_init(): for cls in (SimpleBKZ, SimpleDualBKZ, BKZ, BKZ2): for n in dimensions: set_random_seed(2**10 + n) A = make_integer_matrix(n) B = cls(copy(A)) del B
def test_bkz_call(block_size=10): params = fplll_bkz.Param(block_size=block_size, flags=fplll_bkz.VERBOSE | fplll_bkz.GH_BND) for cls in (BKZ, BKZ2): for n in dimensions: set_random_seed(n) A = make_integer_matrix(n) B = copy(A) cls(B)(params=params)
def test_bkz_call(block_size=10): params = fplll_bkz.Param(block_size=block_size, flags=fplll_bkz.VERBOSE|fplll_bkz.GH_BND) for cls in (BKZ, BKZ2): for n in dimensions: set_random_seed(n) A = make_integer_matrix(n) B = copy(A) cls(B)(params=params)
def test_simple_bkz_reduction(block_size=10): for n in dimensions: set_random_seed(n) A = make_integer_matrix(n) LLL.reduction(A) B = copy(A) BKZ.reduction(B, BKZ.Param(block_size=block_size)) C = copy(A) SimpleBKZ(C)(block_size=block_size) assert abs(C[0].norm() - B[0].norm()) < 0.1 assert abs(C[0].norm() < A[0].norm())
def load_prebkz(n, s=0, blocksize=40): """ """ filename = "qarychallenge/prebkz-%02d-dim-%03d-seed-%02d.txt" % (blocksize, n, s) if not os.path.isdir("qarychallenge"): os.mkdir("qarychallenge") if os.path.isfile(filename) is False: set_random_seed(s) A = IntegerMatrix.random(n, "qary", q=2**30, k=n // 2) print "Did not find '{filename}'. Creating and reducing".format( filename=filename) print "created, ", sys.stdout.flush() A = LLL.reduction(A) print "LLLed, ", sys.stdout.flush() if A.nrows >= 160: float_type = "long double" elif A.nrows >= 200: float_type = "dd" else: float_type = "double" M = GSO.Mat(A, float_type=float_type, flags=GSO.ROW_EXPO) bkz = BKZReduction(M) for b in range(10, blocksize + 1): print "\r created, LLLed, BKZed %d" % b, sys.stdout.flush() par = fplll_bkz.Param(b, strategies=fplll_bkz.DEFAULT_STRATEGY, max_loops=1, flags=fplll_bkz.MAX_LOOPS) bkz(par) print fn = open(filename, "w") fn.write(str(A)) fn.close() return load_matrix_file(filename, randomize=False)
def test_gh(): for n in dimensions: set_random_seed(n) A = make_integer_matrix(n) M = GSO.Mat(A, float_type="ld") M.discover_all_rows() M.update_gso() radius = M.get_r(0, 0) root_det = M.get_root_det(0, n) gh_radius, ge = adjust_radius_to_gh_bound(2000*radius, 0, n, root_det, 1.0) gh1 = gh_radius * 2**ge r = dump_r(M, 0, n) gh2 = gaussian_heuristic(r) assert abs(gh1/gh2 -1) < 0.01
def test_gh(): for n in dimensions: set_random_seed(n) A = make_integer_matrix(n) M = GSO.Mat(A, float_type="ld") M.discover_all_rows() M.update_gso() radius = M.get_r(0, 0) root_det = M.get_root_det(0, n) gh_radius, ge = adjust_radius_to_gh_bound(2000 * radius, 0, n, root_det, 1.0) gh1 = gh_radius * 2**ge r = dump_r(M, 0, n) gh2 = gaussian_heuristic(r) assert abs(gh1 / gh2 - 1) < 0.01
def test_gh(): try: from fpylll.numpy import dump_r except ImportError: return for n in dimensions: set_random_seed(n) A = make_integer_matrix(n) try: M = GSO.Mat(A, float_type="ld") except ValueError: M = GSO.Mat(A, float_type="d") M.discover_all_rows() M.update_gso() radius = M.get_r(0, 0) root_det = M.get_root_det(0, n) gh_radius, ge = adjust_radius_to_gh_bound(2000*radius, 0, n, root_det, 1.0) gh1 = gh_radius * 2**ge r = dump_r(M, 0, n) gh2 = gaussian_heuristic(r) assert abs(gh1/gh2 -1) < 0.01
def test_simple_bkz_call(block_size=10): for cls in (SimpleBKZ, SimpleDualBKZ): for n in dimensions: set_random_seed(n) A = make_integer_matrix(n) cls(A)(block_size=block_size)
def test_simple_bkz_init(): for n in dimensions: set_random_seed(2**10 + n) A = make_integer_matrix(n) B = SimpleBKZ(copy(A)) del B