Exemplo n.º 1
0
 def test_closure(self):
     for m in arange(1, 9):
         x = GF(arange(2**m), m)
         for a in x.elements:
             for b in x.elements:
                 assert_((GF(array([a]), m) +
                          GF(array([b]), m)).elements[0] in x.elements)
                 assert_((GF(array([a]), m) *
                          GF(array([b]), m)).elements[0] in x.elements)
Exemplo n.º 2
0
 def test_minpols(self):
     m = 4
     x = GF(arange(2**m), m)
     z = array([2, 3, 19, 19, 19, 19, 7, 7, 31, 25, 31, 25, 31, 25, 25, 31])
     assert_array_equal(x.minpolys(), z)
     m = 6
     x = GF(array([2, 8, 32, 6, 24, 35, 10, 40, 59, 41, 14, 37]), m)
     z = array([67, 87, 103, 73, 13, 109, 91, 117, 7, 115, 11, 97])
     assert_array_equal(x.minpolys(), z)
Exemplo n.º 3
0
 def test_power_form(self):
     m = 3
     x = GF(arange(1, 2**m), m)
     y = x.tuple_to_power()
     z = GF(array([0, 1, 3, 2, 6, 4, 5]), m)
     assert_array_equal(y.elements, z.elements)
     m = 4
     x = GF(arange(1, 2**m), m)
     y = x.tuple_to_power()
     z = GF(array([0, 1, 4, 2, 8, 5, 10, 3, 14, 9, 7, 6, 13, 11, 12]), m)
     assert_array_equal(y.elements, z.elements)
Exemplo n.º 4
0
 def test_power_form(self):
     m = 3
     x = GF(arange(1, 2**m), m)
     y = x.tuple_to_power()
     z = GF(array([0, 1, 3, 2, 6, 4, 5]), m)
     assert_array_equal(y.elements, z.elements)
     m = 4
     x = GF(arange(1, 2**m), m)
     y = x.tuple_to_power()
     z = GF(array([0, 1, 4, 2, 8, 5, 10, 3, 14, 9, 7, 6, 13, 11, 12]), m)
     assert_array_equal(y.elements, z.elements)
Exemplo n.º 5
0
 def test_minpols(self):
     m = 4
     x = GF(arange(2**m), m)
     z = array([2, 3, 19, 19, 19, 19, 7, 7, 31, 25, 31, 25, 31, 25, 25, 31])
     assert_array_equal(x.minpolys(), z)
     m = 6
     x = GF(array([2, 8, 32, 6, 24, 35, 10, 40, 59, 41, 14, 37]), m)
     z = array([67, 87, 103, 73, 13, 109, 91, 117, 7, 115, 11, 97])
     assert_array_equal(x.minpolys(), z)
Exemplo n.º 6
0
def cyclic_code_genpoly(n, k):
    """
    Generate all possible generator polynomials for a (n, k)-cyclic code.

    Parameters
    ----------
    n : int
        Code blocklength of the cyclic code.

    k : int
        Information blocklength of the cyclic code.

    Returns
    -------
    poly_list : 1D ndarray of ints
        A list of generator polynomials (represented as integers) for the (n, k)-cyclic code.

    """

    if n % 2 == 0:
        raise ValueError("n cannot be an even number")

    for m in arange(1, 18):
        if (2**m - 1) % n == 0:
            break

    x_gf = GF(arange(1, 2**m), m)
    coset_fields = x_gf.cosets()

    coset_leaders = array([])
    minpol_degrees = array([])
    for field in coset_fields:
        coset_leaders = concatenate(
            (coset_leaders, array([field.elements[0]])))
        minpol_degrees = concatenate(
            (minpol_degrees, array([len(field.elements)])))

    y_gf = GF(coset_leaders, m)
    minpol_list = y_gf.minpolys()
    idx_list = arange(1, len(minpol_list))
    poly_list = array([])

    for i in range(1, 2**len(minpol_list)):
        i_array = dec2bitarray(i, len(minpol_list))
        subset_array = minpol_degrees[i_array == 1]
        if int(subset_array.sum()) == (n - k):
            poly_set = minpol_list[i_array == 1]
            gpoly = 1
            for poly in poly_set:
                gpoly_array = dec2bitarray(gpoly, 2**m)
                poly_array = dec2bitarray(poly, 2**m)
                gpoly = bitarray2dec(convolve(gpoly_array, poly_array) % 2)
            poly_list = concatenate((poly_list, array([gpoly])))

    return poly_list.astype(int)
Exemplo n.º 7
0
 def test_order(self):
     m = 4
     x = GF(arange(1, 2**m), m)
     y = x.order()
     z = array([1, 15, 15, 15, 15, 3, 3, 5, 15, 5, 15, 5, 15, 15, 5])
     assert_array_equal(y, z)
Exemplo n.º 8
0
 def test_tuple_form(self):
     m = 3
     x = GF(arange(0, 2**m-1), m)
     y = x.power_to_tuple()
     z = GF(array([1, 2, 4, 3, 6, 7, 5]), m)
     assert_array_equal(y.elements, z.elements)
Exemplo n.º 9
0
 def test_order(self):
     m = 4
     x = GF(arange(1, 2**m), m)
     y = x.order()
     z = array([1, 15, 15, 15, 15, 3, 3, 5, 15, 5, 15, 5, 15, 15, 5])
     assert_array_equal(y, z)
Exemplo n.º 10
0
 def test_tuple_form(self):
     m = 3
     x = GF(arange(0, 2**m - 1), m)
     y = x.power_to_tuple()
     z = GF(array([1, 2, 4, 3, 6, 7, 5]), m)
     assert_array_equal(y.elements, z.elements)
Exemplo n.º 11
0
 def test_multiplication(self):
     m = 3
     x = GF(array([7, 6, 5, 4, 3, 2, 1, 0]), m)
     y = GF(array([6, 4, 3, 1, 2, 0, 5, 7]), m)
     z = GF(array([4, 5, 4, 4, 6, 0, 5, 0]), m)
     assert_array_equal((x * y).elements, z.elements)
Exemplo n.º 12
0
 def test_addition(self):
     m = 3
     x = GF(arange(2**m), m)
     y = GF(array([6, 4, 3, 1, 2, 0, 5, 7]), m)
     z = GF(array([6, 5, 1, 2, 6, 5, 3, 0]), m)
     assert_array_equal((x + y).elements, z.elements)
Exemplo n.º 13
-1
def cyclic_code_genpoly(n, k):
    """
    Generate all possible generator polynomials for a (n, k)-cyclic code.

    Parameters
    ----------
    n : int
        Code blocklength of the cyclic code.

    k : int
        Information blocklength of the cyclic code.

    Returns
    -------
    poly_list : 1D ndarray of ints
        A list of generator polynomials (represented as integers) for the (n, k)-cyclic code.

    """


    if n%2 == 0:
        raise ValueError("n cannot be an even number")

    for m in arange(1, 18):
        if (2**m-1)%n == 0:
            break

    x_gf = GF(arange(1, 2**m), m)
    coset_fields = x_gf.cosets()

    coset_leaders = array([])
    minpol_degrees = array([])
    for field in coset_fields:
        coset_leaders = concatenate((coset_leaders, array([field.elements[0]])))
        minpol_degrees = concatenate((minpol_degrees, array([len(field.elements)])))

    y_gf = GF(coset_leaders, m)
    minpol_list = y_gf.minpolys()
    idx_list = arange(1, len(minpol_list))
    poly_list = array([])

    for i in range(1, 2**len(minpol_list)):
        i_array = dec2bitarray(i, len(minpol_list))
        subset_array = minpol_degrees[i_array == 1]
        if int(subset_array.sum()) == (n-k):
            poly_set = minpol_list[i_array == 1]
            gpoly = 1
            for poly in poly_set:
                gpoly_array = dec2bitarray(gpoly, 2**m)
                poly_array = dec2bitarray(poly, 2**m)
                gpoly = bitarray2dec(convolve(gpoly_array, poly_array) % 2)
            poly_list = concatenate((poly_list, array([gpoly])))

    return poly_list.astype(int)