#
1;
#================================
function
Badd = add(x1,x2)
# description: this function takes two binary vectors
x1,x2, and returns x1+x2
# mode 2.
# usgae: Badd = add(x1,x2)
n=rows(x1);
x3=zeros(n,1);
for i=1:n
m=x1(i)+x2(i);
if
(m==1) (x3(i)=1); endif;
if
(m==2) (x3(i)=0); endif;
endfor;
Badd=x3;
endfunction
#=====================================
function
Code=CodeGen(M)
# description: This function takes a generator of a
certain code and returns
# the code itself. Each row of the matrix M is
one generator.
# usage: Code=CodeGen(M)
[m,n]=size(M);
Prod=1;
for
k=1:m
Prod=Prod*2;
endfor;
C=zeros(Prod,n);
for
i=1:m
C(i,:)=M(i,:);
endfor;
posit=m;
for
i=1:m
for j=i+1:m
#s=zeros(n,1)
x=C(i,:)'
s=x
for
k=j:m
posit=posit+1;
y=C(k,:)'
#qq=add(x,y)
s=add(s,y)
C(posit,:)=s'
endfor;
endfor;
endfor;
Code=C;
endfunction
#=====================================
function
TwoFact=TF(n)
Prod=1;
for i=1:n
Prod=Prod*2;
endfor;
TF=Prod;
endfunction
#=====================================
function
BtoD=BtD(x)
[n,m]=size(x);
N=max(n,m);
s=x(1);
for
i=2:N
s=s+x(i)*TF(i-1);
endfor;
BtD=s;
endfunction
#=====================================
function
Code=CodeGen(M)
# description: This function takes a generator of a
certain code and returns
# the code itself. Each row of the matrix M is
one generator.
# usage: Code=CodeGen(M)
[m,n]=size(M);
Prod=1;
for
k=1:m
Prod=Prod*2;
endfor;
C=zeros(Prod,n);
check=zeros(Prod,1);
for
i=1:m
C(i,:)=M(i,:);
check(i)=BtD(C(i,:)');
endfor;
posit=m;
for
i=1:m
for j=1:m
for
k=1:m
Code=C;
endfunction
#=====================================
function
[MVadd,flag1] = ad(M,v,check)
# description: This function takes a binary
vectors v,a binary matrix M, and
# returns M+v mod 2.
# usgae: [MVadd,flag1]
= ad(M,v,check)
[nn,n]=size(M);flag1=0;M1=M;
x=zeros(n,1);y=zeros(n,1);
for i=1:nn
for j=1:n
x(j)=M1(i,j);
endfor;
#x=M1(i,:)';
y=add(x,v);
for
k=1:8
if (check(k,:)==y')
(flag1=1);
endif;
endfor;
for
j=1:n
M1(i,j)=y(j);
endfor;
endfor;
MVadd=M1;
endfunction
#================
function
[code,cosets] = findC(G)
# usage: [code,cosets]=findC(G)
#
description: This function returns all the cosets of a certain code; where
# G is a generating matrix for the code.
[m,n]=size(G);
dif=n-m;
code=CodeGen(G)
C=code;
Prod=1;
for
k=1:dif
Prod=Prod*2;
endfor;
#
NOTE: Prod gives the number of cosets.
[mm,nn]=size(C);
NN=mm*n;
r=zeros(Prod,NN);
#
The matrix r will include all the cosets of the code. Every row will contain
# one coset. The elements of the coset are placed one after another in
each
# row.
check=zeros(Prod,n);
# This matrix
"check" contains one element of each different coset.
check(1,:)=C(1,:);
temp=[];
for
tt=1:mm
temp=[temp,C(tt,:)];
endfor;
r(1,:)=temp;
count=1;
for
i=1:n
ei=zeros(n,1);
ei(i)=1;
#flag=0;
M=C;
[M,flag]=ad(M,ei,check);
if (flag==0)
count=count+1;
temp=[];
for
tt=1:mm
temp=[temp,M(tt,:)];
endfor;
r(count,:)=temp;
check(count,:)=M(1,:);
endif;
endfor;
#count
check
if (count <
Prod)
for i=1:n
for
j=1:n
z=zeros(n,1);
id=eye(n,n);
ei=eye(i,:);
ej=eye(j,:);
s=zeros(n,1);
s=add(ei,ej);
if
(s <> z)
M=C;
[M,flag]=ad(M,s,check);
if (flag==0)
count=count+1;
temp=[];
for tt=1:mm
temp=[temp,M(tt,:)];
endfor;
r(count,:)=temp;
check(count,:)=M(1,:);
endif;
endif;
endfor;
endfor;
endif;
#count
printf("Cosets:");printf("
");
# The purpose of the
following for loop is to seperate the cosets and write
# them in the
standard form, instead of being placed in one row.
for ii=1:Prod
x=zeros(1,NN);
x=r(ii,:);
Ci=zeros(mm,n);
#for
ww=1:n
# Ci(1,ww)=x(ww);
#endfor;
for jj=1:mm
d=(jj-1)*n;
for
kk=1:n
Ci(jj,kk)=x(d+kk);
endfor;
endfor;
#printf("C(",ii,")");
Ci
endfor;
cosets=r;
endfunction