def test_conway_poly(): assert galois.conway_poly(2, 8) == galois.Poly.Degrees([8, 4, 3, 2, 0]) GF3 = galois.GF(3) assert galois.conway_poly(3, 8) == galois.Poly.Degrees( [8, 5, 4, 2, 1, 0], coeffs=[1, 2, 1, 2, 2, 2], field=GF3) GF5 = galois.GF(5) assert galois.conway_poly(5, 8) == galois.Poly.Degrees([8, 4, 2, 1, 0], coeffs=[1, 1, 3, 4, 2], field=GF5)
def test_conway_poly_exceptions(): with pytest.raises(TypeError): galois.conway_poly(2.0, 3) with pytest.raises(TypeError): galois.conway_poly(2, 3.0) with pytest.raises(ValueError): galois.conway_poly(4, 3) with pytest.raises(ValueError): galois.conway_poly(2, 0) with pytest.raises(LookupError): # GF(2^409) is the largest characteristic-2 field in Frank Luebeck's database galois.conway_poly(2, 410)
def test_is_primitive_poly(): """ Verify the `is_primitive_poly` boolean is calculated correctly for fields constructed with explicitly-specified irreducible polynomials. """ # GF(2^m) with integer dtype poly = galois.conway_poly(2, 32) GF = galois.GF(2**32, irreducible_poly=poly, primitive_element="x", verify=False) assert GF.is_primitive_poly == True # GF(2^m) with object dtype poly = galois.conway_poly(2, 100) GF = galois.GF(2**100, irreducible_poly=poly, primitive_element="x", verify=False) assert GF.is_primitive_poly == True # GF(p^m) with integer dtype poly = galois.conway_poly(3, 20) GF = galois.GF(3**20, irreducible_poly=poly, primitive_element="x", verify=False) assert GF.is_primitive_poly == True # GF(p^m) with object dtype poly = galois.conway_poly(3, 101) GF = galois.GF(3**101, irreducible_poly=poly, primitive_element="x", verify=False) assert GF.is_primitive_poly == True
def test_gf2_output_2(): """ The states of the Galois LFSR generate the binary extension field with the connection polynomial as its irreducible polynomial. """ GF = galois.GF2 poly = galois.conway_poly(2, 8) state = GF([0,0,0,0,0,0,0,1]) lfsr = galois.LFSR(poly, state=state, config="galois") GFE = galois.GF(2**8, irreducible_poly=poly) alpha = GFE.primitive_element for i in range(GFE.order - 1): np.array_equal(lfsr.state, (alpha**i).vector()) lfsr.step()
def test_primitive_elements_exceptions(): p = galois.conway_poly(2, 8) with pytest.raises(TypeError): galois.primitive_elements(p.coeffs) with pytest.raises(TypeError): galois.primitive_elements(p, start=2.0) with pytest.raises(TypeError): galois.primitive_elements(p, stop=256.0) with pytest.raises(TypeError): galois.primitive_elements(p, reverse=1) with pytest.raises(ValueError): galois.primitive_elements(galois.Poly.Random(0)) with pytest.raises(ValueError): galois.primitive_elements(galois.Poly.Random(2)*galois.Poly.Random(2)) with pytest.raises(ValueError): galois.primitive_elements(p, start=200, stop=100)