コード例 #1
0
ファイル: test_galois_lfsr.py プロジェクト: mhostetter/galois
def test_berlekamp_massey_exceptions():
    GF = galois.GF2
    s = GF([0,0,1,1,0,1,1,1,0,1])

    with pytest.raises(TypeError):
        galois.berlekamp_massey(s.view(np.ndarray))
    with pytest.raises(TypeError):
        galois.berlekamp_massey(s, config=1)
    with pytest.raises(TypeError):
        galois.berlekamp_massey(s, state=1)

    with pytest.raises(ValueError):
        galois.berlekamp_massey(np.atleast_2d(s))
    with pytest.raises(ValueError):
        galois.berlekamp_massey(s, config="invalid-argument")
コード例 #2
0
def test_berlekamp_massey_gf2_3():
    """
    Sage:
        F = GF(2)
        s = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1,0,0,1,0,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,0,1,0,1,0,1,1,0,0,1,1,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,0,1,0,1,0,0,0,0,1,1,0,1,0,1,1,1,1,1,1,0,1,0,1,0,1,0,0,0,1,0,0,1,1,1,1,0,0,0,0,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,1,1,1,0,1,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,1,1,1,1,0,0,0,1,1,0,1,0,1,1,1,0,1,1,0,0,0,1,0,0,1,1,1,0,0,1,1,0,1,1,1,1,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,1,1,1,1,1,1,0,1,1]
        s = [F(si) for si in s]
        berlekamp_massey(s).reverse()  # Sage defines polynomial backwards
    """
    GF = galois.GF2
    s = GF([
        1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
        0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0,
        0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1,
        1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1,
        1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
        1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1,
        1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0,
        1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0,
        1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1
    ])
    c_truth = galois.Poly.Degrees([
        100, 57, 56, 55, 52, 48, 47, 46, 45, 44, 43, 41, 37, 36, 35, 34, 31,
        30, 27, 25, 24, 22, 20, 19, 16, 15, 11, 9, 8, 6, 5, 3, 0
    ])
    c = galois.berlekamp_massey(s)
    assert c == c_truth
コード例 #3
0
ファイル: test_galois_lfsr.py プロジェクト: mhostetter/galois
def test_berlekamp_massey_gf2_3():
    """
    Sage:
        F = GF(2)
        s = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1,0,0,1,0,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,0,1,0,1,0,1,1,0,0,1,1,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,0,1,0,1,0,0,0,0,1,1,0,1,0,1,1,1,1,1,1,0,1,0,1,0,1,0,0,0,1,0,0,1,1,1,1,0,0,0,0,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,1,1,1,0,1,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,1,1,1,1,0,0,0,1,1,0,1,0,1,1,1,0,1,1,0,0,0,1,0,0,1,1,1,0,0,1,1,0,1,1,1,1,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,1,1,1,1,1,1,0,1,1]
        s = [F(1) if si == 1 else F(0) for si in s]
        berlekamp_massey(s)
    """
    GF = galois.GF2
    s = GF([1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1,0,0,1,0,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,0,1,0,1,0,1,1,0,0,1,1,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,1,0,1,0,1,0,0,0,0,1,1,0,1,0,1,1,1,1,1,1,0,1,0,1,0,1,0,0,0,1,0,0,1,1,1,1,0,0,0,0,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,1,1,1,0,1,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,1,1,1,1,0,0,0,1,1,0,1,0,1,1,1,0,1,1,0,0,0,1,0,0,1,1,1,0,0,1,1,0,1,1,1,1,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,1,1,1,1,1,1,0,1,1])
    c_truth = galois.Poly.Degrees([100,97,95,94,92,91,89,85,84,81,80,78,76,75,73,70,69,66,65,64,63,59,57,56,55,54,53,52,48,45,44,43,0])
    c = galois.berlekamp_massey(s, config="galois")
    assert c == c_truth
コード例 #4
0
ファイル: test_galois_lfsr.py プロジェクト: mhostetter/galois
def test_berlekamp_massey_gf2_2():
    """
    Sage:
        F = GF(2)
        s = [1,0,0,0,0,0,0,0,1,0,1,1,0,0,0,1,1,1,1,0]
        s = [F(1) if si == 1 else F(0) for si in s]
        berlekamp_massey(s)
    """
    GF = galois.GF2
    s = GF([1,0,0,0,0,0,0,0,1,0,1,1,0,0,0,1,1,1,1,0])
    c_truth = galois.Poly.Degrees([8,6,5,4,0])
    c = galois.berlekamp_massey(s, config="galois")
    assert c == c_truth
コード例 #5
0
def test_berlekamp_massey_gf2_2():
    """
    Sage:
        F = GF(2)
        s = [1,0,0,0,0,0,0,0,1,0,1,1,0,0,0,1,1,1,1,0]
        s = [F(si) for si in s]
        berlekamp_massey(s).reverse()  # Sage defines polynomial backwards
    """
    GF = galois.GF2
    s = GF([1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0])
    c_truth = galois.Poly.Degrees([8, 4, 3, 2, 0])
    c = galois.berlekamp_massey(s)
    assert c == c_truth