示例#1
0
def test_gf_strip():
    assert gf_strip([]) == []
    assert gf_strip([0]) == []
    assert gf_strip([0,0,0]) == []

    assert gf_strip([1]) == [1]
    assert gf_strip([0,1]) == [1]
    assert gf_strip([0,0,0,1]) == [1]

    assert gf_strip([1,2,0]) == [1,2,0]
    assert gf_strip([0,1,2,0]) == [1,2,0]
    assert gf_strip([0,0,0,1,2,0]) == [1,2,0]
def gf_inv(p1,p2,m):
    res = gf_gcdex(gf_strip(p2), p1, m, ZZ)
    if res[2] != [1]:
        print("Nie ma odwrotnego")
    return res[0]
def gf_inv(a):  # irriducible polynomial
    # mod = 0x18f57 => x^16 + x^15 + x^11 + x^10 + x^9 + x^8 + x^6 + x^4 + x^2 + x^1 + 1 Polynome irreductible
    mod = [1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1]
    a = hextolist(a)
    s, t, g = gf_gcdex(ZZ.map(gf_strip(a)), ZZ.map(mod), 2, ZZ)
    return listtohex(s)