Exemplo n.º 1
0
def is_polynomial_irreducible(f, p):
    """
    Rabin's polynomial irreducibility test over finite fields.
    """
    gf_degree = len(f) - 1

    if gf_degree <= 1:
        return True

    monic_field = galois_field_monic(f, p)

    compare_polynomial = [1, 0]

    indices = {gf_degree // i for i in factorint(gf_degree)}

    monomial_base = gf_frobenius_monomial_base(monic_field, p, ZZ)
    h = monomial_base[1]

    for i in range(1, gf_degree):
        if i in indices:
            g = gf_sub(h, compare_polynomial, p, ZZ)

            if gf_gcd(monic_field, g, p, ZZ) != [1]:
                return False

        h = gf_frobenius_map(h, monic_field, monomial_base, p, ZZ)

    return h == compare_polynomial
Exemplo n.º 2
0
def test_gf_frobenius_map():
    f = ZZ.map([2, 0, 1, 0, 2, 2, 0, 2, 2, 2])
    g = ZZ.map([1, 1, 0, 2, 0, 1, 0, 2, 0, 1])
    p = 3
    b = gf_frobenius_monomial_base(g, p, ZZ)
    h = gf_frobenius_map(f, g, b, p, ZZ)
    h1 = gf_pow_mod(f, p, g, p, ZZ)
    assert h == h1
Exemplo n.º 3
0
def test_gf_frobenius_map():
    f = ZZ.map([2, 0, 1, 0, 2, 2, 0, 2, 2, 2])
    g = ZZ.map([1,1,0,2,0,1,0,2,0,1])
    p = 3
    n = 4
    b = gf_frobenius_monomial_base(g, p, ZZ)
    h = gf_frobenius_map(f, g, b, p, ZZ)
    h1 = gf_pow_mod(f, p, g, p, ZZ)
    assert h == h1