# 24.7 Cyclic Codes

Cyclic codes are a very important class of codes. In the next two sections, we’ll meet two of the most useful examples of these codes. In this section, we describe the general framework.

A code $C$ is called **cyclic** if

For example, if $(1\text{,}\text{}1\text{,}\text{}0\text{,}\text{}1)$ is in a cyclic code, then so is $(1\text{,}\text{}1\text{,}\text{}1\text{,}\text{}0)$. Applying the definition two more times, we see that $(0\text{,}\text{}1\text{,}\text{}1\text{,}\text{}1)$ and $(1\text{,}\text{}0\text{,}\text{}1\text{,}\text{}1)$ are also codewords, so all cyclic permutations of the codeword are codewords. This might seem to be a strange condition for a code to satisfy. After all, it would seem to be rather irrelevant that, for a given codeword, all of its cyclic shifts are still codewords. The point is that cyclic codes have a lot of structure, which makes them easier to study. In the case of BCH codes (see Section 24.8), this structure yields an efficient decoding algorithm.

Let’s start with an example. Consider the binary matrix

The rows of $G$ generate a three-dimensional subspace of seven-dimensional binary space. In fact, in this case, the cyclic shifts of the first row give all the nonzero codewords:

Clearly the minimum weight is 4, so we have a cyclic [7, 3, 4] code.

We now show an algebraic way to obtain this code. Let ${\mathbf{Z}}_{2}[X]$ denote polynomials in $X$ with coefficients mod 2, and let ${\mathbf{Z}}_{2}[X]/({X}^{7}-1)$ denote these polynomials mod $({X}^{7}-1)$. For a detailed description of what this means, see Section 3.11. For the present, it suffices to say that working mod ${X}^{7}-1$ means we are working with polynomials of degree less than 7. Whenever we have a polynomial of degree 7 or higher, we divide by ${X}^{7}-1$ and take the remainder.

Let $g(X)=1+{X}^{2}+{X}^{3}+{X}^{4}$. Consider all products

with $f(X)$ of degree $\le 2$. Write the coefficients of the product as a vector $({a}_{0}\text{,}\text{}\dots \text{,}\text{}{a}_{6})$. For example, $g(X)\cdot 1$ yields $(1\text{,}\text{}0\text{,}\text{}1\text{,}\text{}1\text{,}\text{}1\text{,}\text{}0\text{,}\text{}0)$, which is the top row of $G$. Similarly, $g(X)X$ yields the second row of $G$ and $g(X){X}^{2}$ yields the third row of $G$. Also, $g(X)(1+{X}^{2})$ yields $(1\text{,}\text{}0\text{,}\text{}0\text{,}\text{}1\text{,}\text{}0\text{,}\text{}1\text{,}\text{}1)$, which is the sum of the first and third rows of $G$. In this way, we obtain all the codewords of our code.

We obtained this code by considering products $g(X)f(X)$ with $deg(f)\le 2$. We could also work with $f(X)$ of arbitrary degree and obtain the same code, as long as we work mod $({X}^{7}-1)$. Note that $g(X)({X}^{3}+{X}^{2}+1)={X}^{7}-1\text{\hspace{0.17em}}(\mathrm{m}\mathrm{o}\mathrm{d}\text{}2)$. Divide ${X}^{3}+{X}^{2}+1$ into $f(X)$:

with $deg({f}_{1})\le 2$. Then

Therefore, $g(X){f}_{1}(X)$ gives the same codeword as $g(X)f(X)$, so we may restrict to working with polynomials of degree at most two, as claimed.

Why is the code cyclic? Start with the vector for $g(X)$. The vectors for $g(X)X$ and $g(X){X}^{2}$ are cyclic shifts of the one for $g(X)$ by one place and by two places, respectively. What happens if we multiply by ${X}^{3}$? We obtain a polynomial of degree 7, so we divide by ${X}^{7}-1$ and take the remainder:

The remainder yields the vector $(1\text{,}\text{}0\text{,}\text{}0\text{,}\text{}1\text{,}\text{}0\text{,}\text{}1\text{,}\text{}1)$. This is the cyclic shift by three places of the vector for $g(X)$.

A similar calculation for $j=4\text{,}\text{}5\text{,}\text{}6$ shows that the vector for $g(X){X}^{j}$ yields the shift by $j$ places of the vector for $g(X)$. In fact, this is a general phenomenon. If $q(X)={a}_{0}+{a}_{1}X+\cdots +{a}_{6}{X}^{6}$ is a polynomial, then

The remainder is ${a}_{6}+{a}_{0}X+{a}_{1}{X}^{2}+\cdots +{a}_{5}{X}^{6}$, which corresponds to the vector $({a}_{6}\text{,}\text{}{a}_{0}\text{,}\text{}\dots \text{,}\text{}{a}_{5})$. Therefore, multiplying by $X$ and reducing mod ${X}^{7}-1$ corresponds to a cyclic shift by one place of the corresponding vector. Repeating this $j$ times shows that multiplying by ${X}^{j}$ corresponds to shifting by $j$ places.

We now describe the general situation. Let $\mathbf{F}$ be a finite field. For a treatment of finite fields, see Section 3.11. For the present purposes, you may think of $\mathbf{F}$ as being the integers mod $p$, where $p$ is a prime number, since this is an example of a finite field. For example, you could take $\mathbf{F}={\mathbf{Z}}_{2}=\{0\text{,}\text{}1\}$, the integers mod 2. Let $\mathbf{F}[X]$ denote polynomials in $X$ with coefficients in $\mathbf{F}$. Choose a positive integer $n$. We’ll work in $\mathbf{F}[X]/({X}^{n}-1)$, which denotes the elements of $\mathbf{F}[X]$ mod $({X}^{n}-1)$. This means we’re working with polynomials of degree less than $n$. Whenever we encounter a polynomial of degree $\ge n$, we divide by ${X}^{n}-1$ and take the remainder. Let $g(X)$ be a polynomial in $\mathbf{F}[X]$. Consider the set of polynomials

where $f(X)$ runs through all polynomials in $\mathbf{F}[X]$ (we only need to consider $f(X)$ with degree less than $n$, since higher-degree polynomials can be reduced mod ${X}^{n}-1$). Write

The coefficients give us the $n$-dimensional vector $({a}_{0}\text{,}\text{}\dots \text{,}\text{}{a}_{n-1})$. The set of all such coefficients forms a subspace $C$ of $n$-dimensional space ${\mathbf{F}}^{n}$. Then $C$ is a code.

If $m(X)=g(X)f(X)\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{mod}\text{\hspace{0.17em}}\text{\hspace{0.17em}}({X}^{n}-1)$ is any such polynomial, and $s(X)$ is another polynomial, then $m(X)s(X)=g(X)f(X)s(X)\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{mod}\text{\hspace{0.17em}}\text{\hspace{0.17em}}({X}^{n}-1)$ is the multiple of $g(X)$ by the polynomial $f(X)s(X)$. Therefore, it yields an element of the code $C$. In particular, multiplication by $X$ and reducing mod ${X}^{n}-1$ corresponds to a codeword that is a cyclic shift of the original codeword, as above. Therefore, $C$ is cyclic.

The following theorem gives the general description of cyclic codes.

# Theorem

Let $C$ be a cyclic code of length $n$ over a finite field $\mathbf{F}$. To each codeword $({a}_{0}\text{,}\text{}\dots \text{,}\text{}{a}_{n-1})\in C$, associate the polynomial ${a}_{0}+{a}_{1}X+\cdots +{a}_{n-1}{X}^{n-1}$ in $\mathbf{F}[X]$. Among all the nonzero polynomials obtained from $C$ in this way, let $g(X)$ have the smallest degree. By dividing by its highest coefficient, we may assume that the highest nonzero coefficient of $g(X)$ is 1. The polynomial $g(X)$ is called the **generating polynomial** for $C$. Then

$g(X)$ is uniquely determined by $C$.

$g(X)$ is a divisor of ${X}^{n}-1$.

$C$ is exactly the set of coefficients of the polynomials of the form $g(X)f(X)$ with $deg(f)\le n-1-deg(g)$.

Write ${X}^{n}-1=g(X)h(X)$. Then $m(X)\in \mathbf{F}[X]/({X}^{n}-1)$ corresponds to an element of $C$ if and only if $h(X)m(X)\equiv 0\text{\hspace{0.17em}}\mathrm{m}\mathrm{o}\mathrm{d}\text{\hspace{0.17em}}({X}^{n}-1)$.

Proof.

If ${g}_{1}(X)$ is another such polynomial, then $g(X)$ and ${g}_{1}(X)$ have the same degree and have highest nonzero coefficient equal to 1. Therefore, $g(X)-{g}_{1}(X)$ has lower degree and still corresponds to a codeword, since $C$ is closed under subtraction. Since $g(X)$ had the smallest degree among nonzero polynomials corresponding to codewords, $g(X)-{g}_{1}(X)$ must be 0, which means that ${g}_{1}(X)=g(X)$. Therefore, $g(X)$ is unique.

Divide $g(X)$ into ${X}^{n}-1$:

$${X}^{n}-1=g(X)h(X)+r(X)$$for some polynomials $h(X)$ and $r(X)$, with $deg(r)tdeg(g)$. This means that

$$-r(X)\equiv g(X)h(X)\text{\hspace{0.17em}}\mathrm{m}\mathrm{o}\mathrm{d}\text{\hspace{0.17em}}({X}^{n}-1)\text{.}$$As explained previously, multiplying $g(X)$ by powers of $X$ corresponds to cyclic shifts of the codeword associated to $g(X)$. Since $C$ is assumed to be cyclic, the polynomials $g(X){X}^{j}\text{\hspace{0.17em}}\mathrm{m}\mathrm{o}\mathrm{d}\text{\hspace{0.17em}}({X}^{n}-1)$ for $j=0\text{,}\text{}1\text{,}\text{}2\text{,}\text{}\dots $ therefore correspond to codewords; call them ${c}_{0}\text{,}\text{}{c}_{1}\text{,}\text{}{c}_{2}\text{,}\text{}\dots $. Write $h(X)={b}_{0}+{b}_{1}X+\cdots +{b}_{k}{X}^{k}$. Then $g(X)h(X)$ corresponds to the linear combination

$${b}_{0}{c}_{0}+{b}_{1}{c}_{1}+\cdots +{b}_{k}{c}_{k}\text{.}$$Since each ${b}_{i}$ is in $\mathbf{F}$ and each ${c}_{i}$ is in $C$, we have a linear combination of elements of $C$. But $C$ is a vector subspace of $n$-dimensional space ${\mathbf{F}}^{n}$. Therefore, this linear combination is in $C$. This means that $r(X)$, which is $g(X)h(X)\text{\hspace{1em}}\text{mod}\text{\hspace{0.17em}}\text{\hspace{0.17em}}({X}^{n}-1)$, corresponds to a codeword. But $deg(r)tdeg(g)$, which is the minimal degree of a polynomial corresponding to a nonzero codeword in $C$. Therefore, $r(X)=0$. Consequently ${X}^{n}-1=g(X)h(X)$, so $g(X)$ is a divisor of ${X}^{n}-1$.

Let $m(X)$ correspond to an element of $C$. Divide $g(X)$ into $m(X)$:

$$m(X)=g(X)f(X)+{r}_{1}(X)\text{,}\text{}$$with $deg({r}_{1}(X))<deg(g(X))$. As before, $g(X)f(X)\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{mod}\text{\hspace{0.17em}}\text{\hspace{0.17em}}({X}^{n}-1)$ corresponds to a codeword. Also, $m(X)$ corresponds to a codeword, by assumption. Therefore, $m(X)-g(X)f(X)\text{\hspace{0.17em}}\mathrm{m}\mathrm{o}\mathrm{d}\text{\hspace{0.17em}}({X}^{n}-1)$ corresponds to the difference of these codewords, which is a codeword. But this polynomial is just ${r}_{1}(X)={r}_{1}(X)\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{mod}\text{\hspace{0.17em}}\text{\hspace{0.17em}}({X}^{n}-1)$. As before, this polynomial has degree less than $deg(g(X))$, so ${r}_{1}(X)=0$. Therefore, $m(X)=g(X)f(X)$. Since $deg(m)\le n-1$, we must have $deg((f)\le n-1-deg(g)$. Conversely, as explained in the proof of (2), since $C$ is cyclic, any such polynomial of the form $g(X)f(X)$ yields a codeword. Therefore, these polynomials yield exactly the elements of $C$.

Write ${X}^{n}-1=g(X)h(X)$, which can be done by (2). Suppose $m(X)$ corresponds to an element of $C$. Then $m(X)=g(X)f(X)$, by (3), so

$$h(X)m(X)=h(X)g(X)f(X)=({X}^{n}-1)f(X)\equiv 0\text{\hspace{1em}}\text{mod}\text{\hspace{0.17em}}\text{\hspace{0.17em}}({X}^{n}-1)\text{.}$$Conversely, suppose $m(X)$ is a polynomial such that $h(X)m(X)\equiv 0$ $\text{\hspace{0.17em}}\mathrm{m}\mathrm{o}\mathrm{d}\text{\hspace{0.17em}}({X}^{n}-1)$. Write $h(X)m(X)=({X}^{n}-1)q(X)=h(X)g(X)q(X)$, for some polynomial $q(X)$. Dividing by $h(X)$ yields $m(X)=g(X)q(X)$, which is a multiple of $g(X)$, and hence corresponds to a codeword. This completes the proof of the theorem.

Let $g(X)={a}_{0}+{a}_{1}X+\cdots +{a}_{k-1}{X}^{k-1}+{X}^{k}$ be as in the theorem. By part (3) of the theorem, every element of $C$ corresponds to a polynomial of the form $g(X)f(X)$, with $deg(f(X))\le n-1-k$. This means that each such $f(X)$ is a linear combination of the monomials $1\text{,}\text{}X\text{,}\text{}{X}^{2}\text{,}\text{}\dots \text{,}\text{}{X}^{n-1-k}$. It follows that the codewords of $C$ are linear combinations of the codewords corresponding to the polynomials

But these are the vectors

Therefore, a generating matrix for $C$ can be given by

We can use part (4) of the theorem to obtain a parity check matrix for $C$. Let $h(X)={b}_{0}+{b}_{1}X+\cdots +{b}_{l}{X}^{l}$ be as in the theorem (where $l=n-k$). We’ll prove that the $k\times n$ matrix

is a parity check matrix for $C$. Note that the order of the coefficients of $h(X)$ is reversed. Recall that $H$ is a parity check matrix for $C$ means that $H{c}^{T}=0$ if and only if $c\in C$.

# Proposition

$H$ is a parity check matrix for $C$.

Proof. First observe that since $g(X)$ has 1 as its highest nonzero coefficient, and since $g(X)h(X)={X}^{n}-1$, the highest nonzero coefficient ${b}_{l}$ of $h(X)$ must also be 1. Therefore, $H$ is in row echelon form and consequently its rows are linearly independent. Since $H$ has $k$ rows, it has rank $k$. The right null space of $H$ therefore has dimension $n-k$.

Let $m(X)={c}_{0}+{c}_{1}X+\cdots +{c}_{n-1}{X}^{n-1}$. We know from part (4) that $({c}_{0}\text{,}\text{}{c}_{1}\text{,}\text{}\dots \text{,}\text{}{c}_{n-1})\in C$ if and only if $h(X)m(X)\equiv 0\text{\hspace{0.17em}}\mathrm{m}\mathrm{o}\mathrm{d}\text{\hspace{0.17em}}({X}^{n}-1)$.

Choose $j$ with $l\le j\le n-1$ and look at the coefficient of ${X}^{j}$ in the product $h(X)m(X)$. It equals

There is a technical point to mention: Since we are looking at $h(X)m(X)\text{\hspace{0.17em}}\mathrm{m}\mathrm{o}\mathrm{d}\text{\hspace{0.17em}}({X}^{n}-1)$, we need to worry about a contribution from the term ${X}^{n+j}$ (since ${X}^{n+j}\equiv {X}^{n}{X}^{j}\equiv 1\cdot {X}^{j}$, the monomial ${X}^{n+j}$ reduces to ${X}^{j}$). However, the highest-degree term in the product $h(X)m(X)$ before reducing mod ${X}^{n}-1$ is ${c}_{n-1}{X}^{l+n-1}$. Since $l\le j$, we have $l+n-1tj+n$. Therefore, there is no term with ${X}^{n+j}$ to worry about.

When we multiply $H$ times $({c}_{0}\text{,}\text{}{c}_{1}\text{,}\text{}\dots \text{,}\text{}{c}_{n-1}{)}^{T}$, we obtain a vector whose first entry is

More generally, the $i$th entry (where $1\le i\le k$) is

This is the coefficient of ${X}^{l+i-1}$ in the product $h(X)m(X)\text{\hspace{0.17em}}\mathrm{m}\mathrm{o}\mathrm{d}\text{\hspace{0.17em}}({X}^{n}-1)$.

If $({c}_{0}\text{,}\text{}{c}_{1}\text{,}\text{}\dots \text{,}\text{}{c}_{n-1})$ is in $C$, then $h(X)m(X)\equiv 0\text{\hspace{0.17em}}\mathrm{m}\mathrm{o}\mathrm{d}\text{\hspace{0.17em}}({X}^{n}-1)$, so all these coefficients are 0. Therefore, $H$ times $({c}_{0}\text{,}\text{}{c}_{1}\text{,}\text{}\dots \text{,}\text{}{c}_{n-1}{)}^{T}$ is the 0 vector, so the transposes of the vectors of $C$ are contained in the right null space of $H$. Since both $C$ and the null space have dimension $k$, we must have equality. This proves that $c\in C$ if and only if $H{c}^{T}=0$, which means that $H$ is a parity check matrix for $C$.

# Example

In the example at the beginning of this section, we had $n=7$ and $g(X)={X}^{4}+{X}^{3}+{X}^{2}+1$. We have $g(X)({X}^{3}+{X}^{2}+1)={X}^{7}-1$, so $h(X)={X}^{3}+{X}^{2}+1$. The parity check matrix is

The parity check matrix gives a way of detecting errors, but correcting errors for general cyclic codes is generally quite difficult. In the next section, we describe a class of cyclic codes for which a good decoding algorithm exists.