Beispiel #1
0
def test_gf_from_to_dict():
    f = {11: 12, 6: 2, 0: 25}
    F = {11: 1, 6: 2, 0: 3}
    g = [1,0,0,0,0,2,0,0,0,0,0,3]

    assert gf_from_dict(f, 11) == g
    assert gf_to_dict(g, 11) == F

    f = {11: -5, 4: 0, 3: 1, 0: 12}
    F = {11: -5, 3: 1, 0: 1}
    g = [6,0,0,0,0,0,0,0,1,0,0,1]

    assert gf_from_dict(f, 11) == g
    assert gf_to_dict(g, 11) == F
Beispiel #2
0
def test_gf_ddf():
    f = gf_from_dict({15: 1, 0: -1}, 11)
    g = [([1, 0, 0, 0, 0, 10], 1),
         ([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2)]

    assert gf_ddf_zassenhaus(f, 11) == g
    assert gf_ddf_shoup(f, 11) == g

    f = gf_from_dict({63: 1, 0: 1}, 2)
    g = [([1, 1], 1),
         ([1, 1, 1], 2),
         ([1, 1, 1, 1, 1, 1, 1], 3),
         ([1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0,
           0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0,
           0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1], 6)]

    assert gf_ddf_zassenhaus(f, 2) == g
    assert gf_ddf_shoup(f, 2) == g

    f = gf_from_dict({6: 1, 5: -1, 4: 1, 3: 1, 1: -1}, 3)
    g = [([1, 1, 0], 1),
         ([1, 1, 0, 1, 2], 2)]

    assert gf_ddf_zassenhaus(f, 3) == g
    assert gf_ddf_shoup(f, 3) == g

    f = [1, 2, 5, 26, 677, 436, 791, 325, 456, 24, 577]
    g = [([1, 701], 1),
         ([1, 110, 559, 532, 694, 151, 110, 70, 735, 122], 9)]

    assert gf_ddf_zassenhaus(f, 809) == g
    assert gf_ddf_shoup(f, 809) == g

    p = nextprime(int((2**15 * pi).evalf()))
    f = gf_from_dict({15: 1, 1: 1, 0: 1}, p)
    g = [([1, 22730, 68144], 2),
         ([1, 64876, 83977, 10787, 12561, 68608, 52650, 88001, 84356], 4),
         ([1, 15347, 95022, 84569, 94508, 92335], 5)]

    assert gf_ddf_zassenhaus(f, p) == g
    assert gf_ddf_shoup(f, p) == g
Beispiel #3
0
def test_gf_squarefree():
    assert gf_sqf([], 11) == (0, [])
    assert gf_sqf([1], 11) == (1, [])
    assert gf_sqf([1,1], 11) == (1, [([1, 1], 1)])

    assert gf_sqf_p([], 11) == True
    assert gf_sqf_p([1], 11) == True
    assert gf_sqf_p([1,1], 11) == True

    f = gf_from_dict({11: 1, 0: 1}, 11)

    assert gf_sqf_p(f, 11) == False

    assert gf_sqf(f, 11) == \
       (1, [([1, 1], 11)])

    f = [1, 5, 8, 4]

    assert gf_sqf_p(f, 11) == False

    assert gf_sqf(f, 11) == \
        (1, [([1, 1], 1),
             ([1, 2], 2)])
Beispiel #4
0
def gathen_poly(n, p):
    return gf_from_dict({n: 1, 1: 1, 0: 1}, p)
Beispiel #5
0
def test_gf_factor():
    assert gf_factor([], 11) == (0, [])
    assert gf_factor([1], 11) == (1, [])
    assert gf_factor([1,1], 11) == (1, [([1, 1], 1)])

    f, p = [1,0,0,1,0], 2

    g = (1, [([1, 0], 1),
             ([1, 1], 1),
             ([1, 1, 1], 1)])

    assert gf_factor(f, p, method='zassenhaus') == g
    assert gf_factor(f, p, method='shoup') == g

    g = (1, [[1, 0],
             [1, 1],
             [1, 1, 1]])

    assert gf_factor_sqf(f, p, method='zassenhaus') == g
    assert gf_factor_sqf(f, p, method='shoup') == g

    assert gf_factor([1, 5, 8, 4], 11) == \
        (1, [([1, 1], 1), ([1, 2], 2)])

    assert gf_factor([1, 1, 10, 1, 0, 10, 10, 10, 0, 0], 11) == \
        (1, [([1, 0], 2), ([1, 9, 5], 1), ([1, 3, 0, 8, 5, 2], 1)])

    assert gf_factor(gf_from_dict({32: 1, 0: 1}, 11), 11) == \
        (1, [([1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 10], 1),
             ([1, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 10], 1)])

    assert gf_factor(gf_from_dict({32: 8, 0: 5}, 11), 11) == \
        (8, [([1, 3], 1),
             ([1, 8], 1),
             ([1, 0, 9], 1),
             ([1, 2, 2], 1),
             ([1, 9, 2], 1),
             ([1, 0, 5, 0, 7], 1),
             ([1, 0, 6, 0, 7], 1),
             ([1, 0, 0, 0, 1, 0, 0, 0, 6], 1),
             ([1, 0, 0, 0, 10, 0, 0, 0, 6], 1)])

    assert gf_factor(gf_from_dict({63: 8, 0: 5}, 11), 11) == \
        (8, [([1, 7], 1),
             ([1, 4, 5], 1),
             ([1, 6, 8, 2], 1),
             ([1, 9, 9, 2], 1),
             ([1, 0, 0, 9, 0, 0, 4], 1),
             ([1, 2, 0, 8, 4, 6, 4], 1),
             ([1, 2, 3, 8, 0, 6, 4], 1),
             ([1, 2, 6, 0, 8, 4, 4], 1),
             ([1, 3, 3, 1, 6, 8, 4], 1),
             ([1, 5, 6, 0, 8, 6, 4], 1),
             ([1, 6, 2, 7, 9, 8, 4], 1),
             ([1, 10, 4, 7, 10, 7, 4], 1),
             ([1, 10, 10, 1, 4, 9, 4], 1)])

    # Gathen polynomials: x**n + x + 1 (mod p > 2**n * pi)

    p = nextprime(int((2**15 * pi).evalf()))
    f = gf_from_dict({15: 1, 1: 1, 0: 1}, p)

    assert gf_sqf_p(f, p) == True

    g = (1, [([1, 22730, 68144], 1),
             ([1, 81553, 77449, 86810, 4724], 1),
             ([1, 86276, 56779, 14859, 31575], 1),
             ([1, 15347, 95022, 84569, 94508, 92335], 1)])

    assert gf_factor(f, p, method='zassenhaus') == g
    assert gf_factor(f, p, method='shoup') == g

    g = (1, [[1, 22730, 68144],
             [1, 81553, 77449, 86810, 4724],
             [1, 86276, 56779, 14859, 31575],
             [1, 15347, 95022, 84569, 94508, 92335]])

    assert gf_factor_sqf(f, p, method='zassenhaus') == g
    assert gf_factor_sqf(f, p, method='shoup') == g

    # Shoup polynomials: f = a_0 x**n + a_1 x**(n-1) + ... + a_n
    # (mod p > 2**(n-2) * pi), where a_n = a_{n-1}**2 + 1, a_0 = 1

    p = nextprime(int((2**4 * pi).evalf()))
    f = [1, 2, 5, 26, 41, 39, 38]  # deg(f) = 6

    assert gf_sqf_p(f, p) == True

    g = (1, [([1, 44, 26], 1),
             ([1, 11, 25, 18, 30], 1)])

    assert gf_factor(f, p, method='zassenhaus') == g
    assert gf_factor(f, p, method='shoup') == g

    g = (1, [[1, 44, 26],
             [1, 11, 25, 18, 30]])

    assert gf_factor_sqf(f, p, method='zassenhaus') == g
    assert gf_factor_sqf(f, p, method='shoup') == g
def gathen_poly(n, p):
    return gf_from_dict({n: 1, 1: 1, 0: 1}, p)