256個の要素をもつ体 GF (2^8) を用いて符号を構成する。

γ は (γ^8)+(γ^4)+(γ^3)+(γ^2)+1をみたす数とする。

minimal = (γ^8)+(γ^4)+(γ^3)+(γ^2)+1

GF (2^8) のすべての要素を加法表示と乗法表示したもののリストを作る。

additive=Table[
PolynomialMod[γ^(254-i),{minimal ,2}],
{i,0,254}]~
Join~{0};

multiplicative=Table[γ^(254-i),{i,0,254}]~
Join~{0};

toA は加法表示に直すため、toM は乗法表示に直すための関数。

toA[elem_]:=PolynomialMod[elem,{minimal ,2}]

For[i= 1, i<256,i++,toM0[additive[[i]]]=γ^(255-i)];
toM0[0]=0;
toM[elem_]:=toM0[PolynomialMod[elem,{minimal ,2}]]

符号を生成する多項式(x+1)(x+γ)…(x+γ^12)

generator =Collect[Product[x+γ^i,{i,0,12}],x,toM]

encode は13次元ベクトルを25次の符号多項式 （符号語） に直す関数。
まず13次元ベクトルから12次多項式を作り、それを生成多項式にかけて25次多項式を作る。
decode はこれを元に戻す関数。生成多項式による商を取る。

encode[vector_]:=
PolynomialMod[
vector.Table[x^(Length[vector]+13-i),{i,1,Length[vector]}]+
PolynomialMod[vector.Table[x^(Length[vector]+13-i),{i,1,Length[vector]}],{generator,2}],2]

decode[polynomial_]:=
Map[toM,Table[Coefficient[polynomial,x,25-i],{i,0,12}]]

情報ベクトル１={{1,0,0,0,0,0,0,0},{0,1,0,0,0,0,1,0},{1,1,1,0,1,0,0,0},{0,0,1,1,1,1,0,1},{0,1,0,1,1,1,0,1},{1,0,1,1,1,1,1,0},{0,0,0,0,0,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,0,0,0,0,0},{1,1,1,0,1,1,0,0},{0,0,0,1,0,0,0,1},{1,1,1,0,1,1,0,0},{0,0,0,1,0,0,0,1}};

情報ベクトル２=Map[toM[#.Table[(γ^((8-i))),{i,1,8}]]&,情報ベクトル１]

具体例：情報ベクトル２を２５次の符号多項式に直す。

sent=Collect[encode[情報ベクトル２],x,toM]

m011={{0,1,1,0,0,0,0,1},{1,0,0,0,0,1,1,0},{0,0,0,1,1,0,0,0},{1,0,0,1,0,0,1,0},{0,1,0,0,1,0,0,1},{0,0,1,0,0,1,0,0},{1,0,0,0,0,1,1,0},{0,0,0,1,1,0,0,0},{0,1,1,0,0,0,0,1},{0,0,1,0,0,1,0,0},{1,0,0,1,0,0,1,0},{0,1,0,0,1,0,0,1},{0,0,0,1,1,0,0,0},{0,1,1,0,0,0,0,1},{1,0,0,0,0,1,1,0},{0,0,0,1,0,0,0,1},{1,0,0,0,0,1,1,0},{0,1,0,0,1,0,0,1},{0,0,1,0,0,0,1,0},{0,1,0,0,1,0,0,1},{0,0,1,0,0,1,0,0},{1,0,0,1,0,0,1,0},{0,0,0,1,1,0,0,0},{0,0,1,0,0,1,0,0},{1,0,0,1,0,0,1,0},{0,1,0,0,1,0,0,1}};

decode[sent]

Mod[Map[Table[Coefficient[toA[#],γ,7-i],{i,0,7}] &,Table[Coefficient[sent,x,25-i],{i,0,25}]]+m011,2]

[

Map[Table[Coefficient[toA[#],γ,i],{i,0,7}] &,CoefficientList[sent,x]]+m011

decode[sent]

ノイズを加えてみる。

received=PolynomialMod[sent+(γ^2)(x^6)+(γ^12)(x^7)+(γ^231)(x^12),2]

間違いを訂正せずにベクトルに戻してみる。

decode[received]

元と較べると

decode[sent]

シンドロームを計算する

(Subscript[s, 1])=toM[received/.x->γ]
(Subscript[s, 2])=toM[received/.x->(γ^2)]
(Subscript[s, 3])=toM[received/.x->(γ^3)]
(Subscript[s, 4])=toM[received/.x->(γ^4)]
(Subscript[s, 5])=toM[received/.x->(γ^5)]

誤りを解に持つ３次方程式を作る。

eq=toM[(((Subscript[s, 1])^3)+(Subscript[s, 3]))]X^3 +
toM[ (Subscript[s, 1])(((Subscript[s, 1])^3)+(Subscript[s, 3])) ]X^2 + 
toM[(((Subscript[s, 1])^2)(Subscript[s, 3])+(Subscript[s, 5]))]X +
toM[(((Subscript[s, 1])^3) + (Subscript[s, 3]))((Subscript[s, 1])^3) +((Subscript[s, 3])^2)+(Subscript[s, 1]) (Subscript[s, 5])]

(α^i)を次々に代入し０になる場所を見る。

Table[PolynomialMod[eq/.X->(α^i),{minimal,2}],{i,0,14}]