galois.BCH.encode(message: ArrayLike, output: 'codeword' | 'parity' = 'codeword') FieldArray

Encodes the message m into the codeword c.

Parameters:
message: ArrayLike

The message as either a k-length vector or (N,k) matrix, where N is the number of messages.

Shortened codes

For the shortened [ns, ks, d] code (only applicable for systematic codes), pass ks symbols into encode() to return the ns-symbol message.

output: 'codeword' | 'parity' = 'codeword'

Specify whether to return the codeword or parity symbols only. The default is "codeword".

Returns:

If output="codeword", the codeword as either a n-length vector or (N,n) matrix. If output="parity", the parity symbols as either a nk-length vector or (N,nk) matrix.

Notes

The message vector m is a member of GF(q)k. The corresponding message polynomial m(x) is a degree-k polynomial over GF(q).

m=[mk1, , m1, m0]GF(q)k
m(x)=mk1xk1++m1x+m0GF(q)[x]

The codeword vector c is a member of GF(q)n. The corresponding codeword polynomial c(x) is a degree-n polynomial over GF(q).

c=[cn1, , c1, c0]GF(q)n
c(x)=cn1xn1++c1x+c0GF(q)[x]

The codeword vector is computed by matrix multiplication of the message vector with the generator matrix. The equivalent polynomial operation is multiplication of the message polynomial with the generator polynomial.

c=mG
c(x)=m(x)g(x)

Examples

Encode a single message using the BCH(15,7) code.

In [1]: bch = galois.BCH(15, 7)

In [2]: GF = bch.field

In [3]: m = GF.Random(bch.k); m
Out[3]: GF([0, 1, 0, 1, 0, 0, 0], order=2)

In [4]: c = bch.encode(m); c
Out[4]: GF([0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1], order=2)

Compute the parity symbols only.

In [5]: p = bch.encode(m, output="parity"); p
Out[5]: GF([0, 1, 1, 0, 1, 0, 0, 1], order=2)

Encode a single message using the shortened BCH(12,4) code.

In [6]: bch = galois.BCH(15, 7)

In [7]: GF = bch.field

In [8]: m = GF.Random(bch.k - 3); m
Out[8]: GF([1, 0, 1, 0], order=2)

In [9]: c = bch.encode(m); c
Out[9]: GF([1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0], order=2)

Compute the parity symbols only.

In [10]: p = bch.encode(m, output="parity"); p
Out[10]: GF([0, 1, 1, 0, 1, 1, 1, 0], order=2)

Encode a matrix of three messages using the BCH(15,7) code.

In [11]: bch = galois.BCH(15, 7)

In [12]: GF = bch.field

In [13]: m = GF.Random((3, bch.k)); m
Out[13]: 
GF([[0, 0, 0, 0, 1, 1, 0],
    [1, 1, 0, 0, 1, 0, 1],
    [0, 1, 0, 1, 1, 1, 0]], order=2)

In [14]: c = bch.encode(m); c
Out[14]: 
GF([[0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1],
    [1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1],
    [0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0]], order=2)

Compute the parity symbols only.

In [15]: p = bch.encode(m, output="parity"); p
Out[15]: 
GF([[1, 0, 0, 1, 0, 1, 0, 1],
    [1, 0, 1, 0, 1, 0, 1, 1],
    [1, 1, 1, 1, 1, 1, 0, 0]], order=2)

Encode a matrix of three messages using the shortened BCH(12,4) code.

In [16]: bch = galois.BCH(15, 7)

In [17]: GF = bch.field

In [18]: m = GF.Random((3, bch.k - 3)); m
Out[18]: 
GF([[1, 0, 0, 0],
    [1, 1, 1, 0],
    [1, 1, 1, 1]], order=2)

In [19]: c = bch.encode(m); c
Out[19]: 
GF([[1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1],
    [1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0],
    [1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1]], order=2)

Compute the parity symbols only.

In [20]: p = bch.encode(m, output="parity"); p
Out[20]: 
GF([[0, 0, 0, 1, 1, 1, 0, 1],
    [1, 0, 0, 0, 1, 0, 0, 0],
    [0, 1, 0, 1, 1, 0, 0, 1]], order=2)