Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168739
Image: ubuntu2004

Cyclic Codes

A right cyclic shift is where each entry of a vector is shifted one place to the right, and the last entry is shifted to the first position.

Right cyclic shift σ:FqnFqn\sigma:\mathbb{F}_q^n\rightarrow \mathbb{F}_q^n

            v=a0a1...an1σ(v)=an1a0...an2v=a_0a_1...a_{n-1}\mapsto \sigma(v)=a_{n-1}a_0...a_{n-2}

  An linear code is CYCLIC if σ(C)C\sigma(C)\subseteq C, that is, for all vCv\in C, the right cyclic shift of vv is also in CC.

Polynomials modulo (1xn1-x^n)

We can represent codewords of length nn by polynomials of degree n1n-1.

Polynomial Representation  π:FqnFq[x]/(1xn)\pi:\mathbb{F}_q^n\rightarrow \mathbb{F}_q[x]/(1-x^n)

v=a0a1...an1π(v)=a0+a1x+a2x2+...+an1xn1v=a_0a_1...a_{n-1} \mapsto \pi(v)=a_0+a_1x+a_2x^2+...+a_{n-1}x^{n-1}.

Algebra  Addition is as usual. We can now also multiply words (modulo 1xn1-x^n).

Example:

F2[x]/(1x3)={0,1,x,x2,1+x,1+x2,x+x2,1+x+x2}\mathbb{F}_2[x]/(1-x^3)=\{0,1,x,x^2,1+x,1+x^2,x+x^2,1+x+x^2\}

Ex 1 Let v=101v=101 and w=010w=010, then π(v)π(w)=(1+x2)(x)=x+x31+x(mod1x3)\pi(v)\pi(w)=(1+x^2)(x)=x+x^3\equiv 1+x \pmod{1-x^3}

Ex 2 Let v=101v=101 and w=111w=111, then π(v)π(w)=(1+x2)(1+x+x2)0(mod1x3)\pi(v)\pi(w)=(1+x^2)(1+x+x^2)\equiv 0 \pmod{1-x^3}

We have now defined a multiplication operation on codewords. This is not an inner product.

In Ex 2 vw=0, and we can see that we now have zero divisors.

A cyclic shift corresponds to multiplication by x.

π(σ(v))=xπ(v)\pi(\sigma(v))=x\pi(v)

Classifying Cyclic Codes

Theorem A linear code CC is cyclic if and only if for every codeword vCv\in C and every word wFqnw\in \mathbb{F}_q^n, we have wvC wv \in C.

Theorem A linear code CC is cyclic if and only if  fπ(v)π(C)f\pi(v)\in\pi(C) for every vCv\in C and every fFq[x]f\in\mathbb{F}_q[x].

                       CC cyclic code over Fqπ(C)\mathbb{F}_q \longleftrightarrow \pi(C) is an ideal of Fq[x]/(1xn)\mathbb{F}_q[x]/(1-x^n).


Creating Cyclic codes

To create a cyclic code as words we can do the following:

Let vFqnv\in \mathbb{F}_q^n and let S={v,σ(v),σ2(v),...,σn1v}S=\{v,\sigma(v),\sigma^2(v),...,\sigma^{n-1}v\}.

In general the elements of SS are not all distinct. Then C=SC=\langle S\rangle is the cyclic code genreated by vv.

To create a cyclic code as polynomials:

S={π(v),xπ(v),x2π(v),...,xn1π(v)}S=\{\pi(v),x\pi(v),x^2\pi(v),...,x^{n-1}\pi(v)\}.

The codewords are exactly the polynomial multiples of π(v)\pi(v).

C=SC=\langle S \rangle is the cyclic code generated by π(v)\pi(v).

The word vv or its polynomial version π(v)\pi(v) is called a generator for CC.

There can be several generators for a code, but we are concerned with finding the generator of CC.

Theorem

Let CC be a cyclic code over Fq\mathbb{F}_q. There exists a unique monic polynomial in CC with minimal degree.


This polynomial gg is called the generator of CC.

Theorem

C=gC=\langle g \rangle.

Proof: (\supseteq) is obvious. Now let fCf\in C. By the Division Algorithm, f=gq+rf=gq+r with deg(r)<(r)<deg(g)(g), but r=fgqC,r=f-gq \in C, \rightarrow\leftarrow

So r=0r=0 and ff is a multiple of gg so fgf\in\langle g \rangle.

Theorem

If ff is a generator for a cyclic code of length nn, then g:=gcd(f,1xn)g:=\gcd(f,1-x^n) is the generator for the code.

Proof: Since gf(mod1xn)g\equiv f \pmod{1-x^n} then gf=C\langle g \rangle \subseteq \langle f \rangle=C.

         Since gg divides ff, fg\langle f \rangle \subseteq \langle g \rangle. Now assume hh is the generator polynomial of CC.

         Then gg divides HH, and deg(g)<(g)<deg(h)(h). Hence by minimality, g=hg=h.
Theorem

There is a one-to-one correspondence between cyclic codes of length nn and the monic divisors of (1xn)(1-x^n) in Fq\mathbb{F}_q.

If 1xn=i=1rpiei1-x^n=\prod_{i=1}^r p_i^{e_i} in Fq\mathbb{F}_q is the factorization into irreducible monic polynomials, then there are i=1r(ei+1)\prod_{i=1}^r (e_i+1) different cyclic codes over Fq\mathbb{F}_q.

Properites of Cyclic Codes

1. If the generator polynomial for a cyclic code CC is of degree rr, then the dimension of CC is nrn-r.

2. If gg is the generator polynomial for a code CC of degree rr, the set S={g,xg,x2g,...,xk1g}S=\{g,xg,x^2g,...,x^{k-1}g\} is linearly indedependent where k=nrk=n-r. In fact, it is a basis for CC.

3. A cyclic code CC of length nn and dimension kk exists if and only if there is a polynomial gg of degree nkn-k which divides (1xn)(1-x^n).

4. A generator matrix for CC is gxgx2gxk1g\left| \begin{matrix} g\\xg\\x^2g\\ \vdots \\ x^{k-1}g \end{matrix}\right|


Constructing Cyclic Codes From Polynomials in Sage

It is easy to construct cyclic codes in Sage. First you construct the polynomial ring over the field you are working in. Then you name your generator polynomial, and finally, you construct your code.

P.<x>=PolynomialRing(GF(3),"x") g=x-1 C=CyclicCodeFromGeneratingPolynomial(4,g);C
Linear code of length 4, dimension 3 over Finite Field of size 3
P.<x>=PolynomialRing(GF(4,"a"),"x") g=x^3+1 C=CyclicCodeFromGeneratingPolynomial(9,g);C
Linear code of length 9, dimension 6 over Finite Field in a of size 2^2

You can still get a generator matrix for your code, but Sage will give it to you in terms of words and not polynomials. You can easily convert back and forth however.

C.gen_mat()
[1 0 0 1 0 0 0 0 0] [0 1 0 0 1 0 0 0 0] [0 0 1 0 0 1 0 0 0] [0 0 0 1 0 0 1 0 0] [0 0 0 0 1 0 0 1 0] [0 0 0 0 0 1 0 0 1]

If your generator does not divide 1xn1-x^n where nn is the length of your code, Sage will find the gcd of your generator and 1xn1-x^n, which is one. Consequently, Sage will use 1 as the generator polynomial. To avoid this,  add the parameter  ignore=false. Then if your generator does not divide 1xn1-x^n you will get the following error message:

P.<x>=PolynomialRing(GF(4,"a"),"x") g=x C=CyclicCodeFromGeneratingPolynomial(5,g,ignore=false);C
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_3.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("UC48eD49UG9seW5vbWlhbFJpbmcoR0YoNCwiYSIpLCJ4IikKZz14CkM9Q3ljbGljQ29kZUZyb21HZW5lcmF0aW5nUG9seW5vbWlhbCg1LGcsaWdub3JlPWZhbHNlKTtD"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmp3dKpSX/___code___.py", line 5, in <module> exec compile(u'C=CyclicCodeFromGeneratingPolynomial(_sage_const_5 ,g,ignore=false);C' + '\n', '', 'single') File "", line 1, in <module> File "/sagenb/sage_install/sage-4.8-sage.math.washington.edu-x86_64-Linux/local/lib/python2.6/site-packages/sage/coding/code_constructions.py", line 676, in CyclicCodeFromGeneratingPolynomial raise ValueError, '%s must divide x^%s - 1'%(g,n) ValueError: x must divide x^5 - 1
P.<x>=PolynomialRing(GF(4,"a"),"x") g=x^3+1 C=CyclicCodeFromGeneratingPolynomial(9,g,ignore=false);C
Linear code of length 9, dimension 6 over Finite Field in a of size 2^2

You can also determine if a poynomial divides 1xn 1-x^n by dividing. If you get a quotient then it is divisible. If Sage presents the answer as a fraction, then it isn't. You must have already defined your polynomial ring. Sage will also factor for you.

(1-x^9)/(1+x^3)
x^6 + x^3 + 1
(1-x^5)/x
(x^5 + 1)/x
P.<x>=PolynomialRing(GF(3),"x") (x^8-1).factor()
(x + 1) * (x + 2) * (x^2 + 1) * (x^2 + x + 2) * (x^2 + 2*x + 2)

To find all of the generators of cyclic codes over Fq\mathbb{F}_q of length nn, you need to the factorization of 1xn1-x^n over Fq\mathbb{F}_q. This can be done in the way that we did it when studying minimal polynomials. On pages 140 and 141 of the text, there are tables of the factorization of xn1x^n-1 for 1n10 1\leq n \leq 10 over F2\mathbb{F}_2 and F3\mathbb{F}_3.

Encoding

Non-systematic encoding is an easier method of encoding than systematic encoding, but systematic encoding makes decoding easier.

Non-systematic Encoding

Generator Polynomial gg of degree rr, for an [n,k=nr][n,k=n-r]-code CC.

G=gxgx2gxk1gG=\left|\begin{matrix} g\\xg\\x^2g\\ \vdots \\ x^{k-1}g \end{matrix} \right|.

Let mm be the original message  of length kk, which is a polynomial of degree k1\leq k-1.

Encoding v=mGv=mG:   v=mg(mod1xn)v=m\cdot g \pmod{1-x^n}.

This is easy encoding, but can you see mm or HH?

Systematic Encoding

We build a generator matrix in the form g=[RIk]g=[R|I_k].

Let rixnk+i(modg)r_i\equiv x^{n-k+i} \pmod{g} for i=0...k1i=0...k-1.

Then ri+xnk+iC -r_i+x^{n-k+i}\in C. In fact, they are linearly independent.

G=r0+xnkr1+xnk+1rk1+xn1G'=\left|\begin{matrix} -r_0 &+& x^{n-k}\\-r_1& +& x^{n-k+1}\\ \cdots &&\cdots\\-r_{k-1}&+&x^{n-1} \end{matrix}\right|.

G=[RIk]G'=[R|I_k] where ri-r_i are the rows of RR.

The original message mm is of length kk, and is a polynomial of degree k1\leq k-1.

Encoding v=mGv=mG'v=qg=r+mxnkv=qg=-r+m\cdot x^{n-k}. rr is the remainder when dividing mxnkmx^{n-k} by gg.

Advantage: Original message mm appears on the last kk positions of vv.

Example:

Let C=2+x+2x3+x4F38C=\langle 2+x+2x^3+x^4\rangle \subseteq \mathbb{F}_3^8.

g=2+x+2x3+x4g=2+x+2x^3+x^4

  r=4r=4, so to make the generator matrix for the code in symmetric form, we need to compute the remainders when x4x^4, x5x^5, x6x^6 and x7x^7 are divided by gg.

For that purpose, we can set up a polynomial ring modulo gg.

R.<u> = QuotientRing(GF(3)[x], GF(3)[x].ideal(x^4+2*x^3+x+2)); R
Univariate Quotient Polynomial Ring in u over Finite Field of size 3 with modulus x^4 + 2*x^3 + x + 2
u^4,u^5,u^6,u^7
(u^3 + 2*u + 1, u^3 + 2*u^2 + 1, 1, u)

To make the generator matrix for the code in symmetric form,

the rows , of the matrix are ri+xnk+i-r_i +x^{n-k+i} for i{0,...,k1}i \in \{0,...,k-1\}.  as shown above.

Thus they are

2+x+2x3+x4=2 10210002+x+2x^3+x^4= 2  1 0 2 1 0 0 0

2+x2+2x3+x5=201101002+x^2+2x^3+x^5=2 0 1 1 0 1 0 0

2+x6=100000102+x^6=1 0 0 0 0 0 1 0

2x+x7=020000012x+x^7=0 2 0 0 0 0 0 1

M=MatrixSpace(GF(3),4,8) G=M([[2,1,0,2,1,0,0,0],[2,0,1,1,0,1,0,0],[1,0,0,0,0,0,1,0],[0,2,0,0,0,0,0,1]]);G
[2 1 0 2 1 0 0 0] [2 0 1 1 0 1 0 0] [1 0 0 0 0 0 1 0] [0 2 0 0 0 0 0 1]

So to encode the message 2010, we mulitply the message by GG and get:

V=VectorSpace(GF(3),4) m=V([2,0,1,0]) m*G
(2, 2, 0, 1, 2, 0, 1, 0)

Note that the message is on the last four digits.

Now to encode via polynomials:

R.<u> = QuotientRing(GF(3)[x], GF(3)[x].ideal(1-x^8)); R (2+u^2)*(2+u+2*u^3+u^4)
u^6 + 2*u^5 + 2*u^4 + 2*u^3 + 2*u^2 + 2*u + 1

So the encoded message is 1 2 2 2 2 2 1 0.

Homework #6

1. Describe all of the ternary cyclic codes of length 4 by giving its generator polynomial and its parameters.

2. Assume C1C_1 and C2C_2 are cyclic codes of the same length with generator polynomials g1(x)g_1(x), g2(x)g_2(x) respectively. Show that C1C2C_1\subseteq C_2 if and only if g2(x)g_2(x) divides g1(x)g_1(x).

3. Problem 7.1

4. Problem 7.6

5. Problem 7.9

6. Problem 7.13

7. Problem 7.23

If you are taking Math 527 then do Problem 7.24.

If you are not taking Math 527 you can do Problem 7.24 for extra credit.