galois.poly_to_generator_matrix(n: int, generator_poly: Poly, systematic: bool = True) FieldArray

Converts the generator polynomial \(g(x)\) into the generator matrix \(\mathbf{G}\) for an \([n, k]\) cyclic code.

Parameters
n: int

The codeword size \(n\).

generator_poly: Poly

The generator polynomial \(g(x)\).

systematic: bool = True

Optionally specify if the encoding should be systematic, meaning the codeword is the message with parity appended. The default is True.

Returns

The \((k, n)\) generator matrix \(\mathbf{G}\), such that given a message \(\mathbf{m}\), a codeword is defined by \(\mathbf{c} = \mathbf{m}\mathbf{G}\).

Examples

Compute the generator matrix for the \(\mathrm{Hamming}(7, 4)\) code.

In [1]: g = galois.primitive_poly(2, 3); g
Out[1]: Poly(x^3 + x + 1, GF(2))

In [2]: galois.poly_to_generator_matrix(7, g, systematic=False)
Out[2]: 
GF([[1, 0, 1, 1, 0, 0, 0],
    [0, 1, 0, 1, 1, 0, 0],
    [0, 0, 1, 0, 1, 1, 0],
    [0, 0, 0, 1, 0, 1, 1]], order=2)

In [3]: galois.poly_to_generator_matrix(7, g, systematic=True)
Out[3]: 
GF([[1, 0, 0, 0, 1, 0, 1],
    [0, 1, 0, 0, 1, 1, 1],
    [0, 0, 1, 0, 1, 1, 0],
    [0, 0, 0, 1, 0, 1, 1]], order=2)