Exemple #1
0
def load_matrix_file(filepath,
                     randomize=False,
                     seed=None,
                     float_type="double"):
    """
    Load matrix from file, LLL reduce (and randomize).

    :param filepath: Load matrix from this file
    :param randomize: Randomize the basis
    :param seed: Seed for randomization
    :returns: lattice basis and BKZ object

    """
    A = IntegerMatrix.from_file(filepath)
    A = LLL.reduction(A)
    A = IntegerMatrix.from_matrix(A, int_type="long")

    M = GSO.Mat(A, float_type=float_type)
    bkz = BKZReduction(M)

    if seed is not None:
        FPLLL.set_random_seed(seed)

    if randomize:
        bkz.randomize_block(0, A.nrows, density=A.ncols // 4)
        LLL.reduction(A)
        M = GSO.Mat(A, float_type=float_type)
        bkz = BKZReduction(M)

    bkz.lll_obj()  # to initialize bkz.M etc

    return A, bkz
Exemple #2
0
def load_challenge_and_randomize(n):
    A_pre = IntegerMatrix.from_file("svpchallenge/svpchallengedim%dseed0.txt" %
                                    n)
    LLL.reduction(A_pre)
    A = IntegerMatrix.from_matrix(A_pre, int_type="long")
    params = fplll_bkz.Param(block_size=n,
                             max_loops=1,
                             strategies=fplll_bkz.DEFAULT_STRATEGY,
                             flags=fplll_bkz.GH_BND,
                             min_success_probability=.8)
    bkz = BKZReduction(A)
    bkz.lll_obj()
    bkz.randomize_block(0, n, density=n / 4)
    bkz.lll_obj()
    return A, bkz
Exemple #3
0
        print "OPPORT_ENUM", {
            "n": n,
            "Time": round(ENUM_TIME, 2),
            "ghf": round(r0 / gh, 4)
        }
        AV_ENUM += ENUM_TIME / sample_rep

        ########### Timing SubSieve
        A, bkz = load_challenge_and_randomize(n)

        SUBSIEVE_START = time()
        d = iterated_sub_sieve(A, goal=goal)
        SUBSIEVE_TIME = time() - SUBSIEVE_START

        bkz = BKZReduction(A)
        bkz.lll_obj()
        r0 = bkz.M.get_r(0, 0)

        print "SUB_SIEVE  ", {
            "n": n,
            "Time": round(SUBSIEVE_TIME, 2),
            "ghf": round(r0 / gh, 4)
        }, {
            "d": d
        }
        AV_SIEVE += SUBSIEVE_TIME / sample_rep

    print
    print "OPPORT_ENUM average :", AV_ENUM
    print "SUB_SIEVE   average :", AV_SIEVE
    print "ratio :", AV_SIEVE / AV_ENUM