Кодирующее устройство для кода Файера
Mass2 = array[1 .. _M] of byte;
Mass3 = array[1 .. _M-1] of byte;
Mas_Exit=array[1..2] of String;
Two_Matrix=array[1 .. _N,1 .. _N+_M-1] of byte;
Const
P : Mass2 = (1,0,1,1,0,0,1,0,1,1);
Y_No : Mas_Exit = ('Да','Нет');
Var
F,Cicle_Kod : Mass1; R : Mass1;
Delimoe : Delim_Mas;
Obraz_Matrix : Two_Matrix;
Mas : Mass;
grDriver,grMode,ErrCode: Integer;
flag : boolean;
_t,c,n,m,i,schot,N0,Code : integer;
Function Sum(F,P : Byte) : Byte; {Суммирование по модулю 2}
Var
i : Byte;
Begin
If ((F=1) and (P=1)) or ((F=0) and (P=0)) Then Sum:=0
Else Sum:=1;
End;
{-------------------------------}
Procedure Dopoln(Var F : Mass1); {Умножение на старшую степень образующего многочлена}
Var
i : Byte;
Begin
for i:=_N+1 to _N+_M-1 do F[i]:=0;
End;
{--------------------------------}
Procedure Delenye(F : Mass1;P : Mass2); {Деление многочлен на многочлен}
Var
i,j,t : Byte; K : Mass1;
Begin
For i:=1 to _N do
Begin
IF F[i]=1 Then Begin
t:=1;
For j:=i to i+_M-1 do
Begin
K[j]:=Sum(F[j],P[t]);
F[j]:=K[j];
t:=t+1;
End;
End;
End;
t:=1;
For i:=_N+1 to _N+_M-1 do
Begin
R[t]:=F[i];
t:=t+1;
End;
End;
{----------------------------------------}
Procedure Ed_Matrix(Var A : Two_Matrix); {Составление еденичной матрицы}
Var
i : Integer;
Begin
For i:=1 to _N do
Begin
A[i,_N+1-i]:=1
End;
End;
{----------------------------------------}
Procedure Obr_Matrix(Var A : Two_Matrix); {Получение образующей матрицы}
Var
i,j,t,Schot,l,m : Byte; K : Mass1;
Begin
Delimoe[1]:=1;
Schot:=1;
For i:=1 to _N do
Begin
IF Delimoe[i]=1 Then Begin
t:=1;
For j:=i to i+_M-1 do
Begin
K[j]:=Sum(Delimoe[j],P[t]);
Delimoe[j]:=K[j];
t:=t+1;
End;
l:=1;
For m:=i+1 to i+_M-1 do
Begin
A[Schot,_N+l]:=Delimoe[m];
l:=l+1;
End;
End
Else Begin
l:=1;
For m:=i+1 to i+_M-1 do
Begin
A[Schot,_N+l]:=Delimoe[m];
l:=l+1;
End;
End;
Schot:=Schot+1;
End;
End;
Procedure InitGrf; {Инициализация графики}
Begin
grDriver := Detect;
InitGraph(grDriver, grMode,'c:subbpbgi');
if GraphResult <> grOk then Begin
Halt(1);
End;
End;
Procedure Visual(Var sa:mass); {Ввод информационных символов}
Var i,x,y,k,Fon,Color,a:Integer;
Code: Integer;
ch,chi:Char;
Stop:Boolean;
Elm : String;
Begin
moveto(20,465);
SetTextJustify(0,1);
SetColor(0);
outtext('Нажмите Enter');
x:=30;
y:=225;
k:=17;
Fon:=1;
Color:=14;
Window_(30,150,610,260,1,'Ввод нформационных символов');
SetTextStyle(1,0,4);
SetColor(Fon);
For i:=1 to _N Do
Begin
MoveTo(x+i*k,y);
Str(Sa[i],Elm);
OutText(Elm);
End;
SetTextStyle(0,0,1);
MoveTo(x+17,y-20);
Str(_N,Elm);
OutText(Elm);
MoveTo(x+_N*17,y-20);
Str(0,Elm);
OutText(Elm);
SetTextStyle(1,0,4);
i:=1;
MoveTo(x+i*k,y);
Setcolor(Color);
Str(Sa[i],Elm);
OutText(Elm);
Stop:=False;
Repeat
Begin
ch:=ReadKey;
Case ch Of
#75:Begin
Setcolor(Fon);
MoveTo(x+i*k,y);
Str(Sa[i],Elm);
OutText(Elm);
i:=i-1;
if(i<1)then i:=_N;
SetColor(Color);
MoveTo(x+i*k,y);
Str(Sa[i],Elm);
OutText(Elm);
Stop:=False;
End;{влево}
#77:Begin
SetColor(Fon);
MoveTo(x+i*k,y);
Str(Sa[i],Elm);
OutText(Elm);
i:=i+1;
if(i>_N)then i:=1;
SetColor(Color);
MoveTo(x+i*k,y);
Str(Sa[i],Elm);
OutText(Elm);
Stop:=False;
End;{вправо}
'1':Begin
SetColor(7);
MoveTo(x+i*k,y);
Str(Sa[i],Elm);
OutText(Elm);
SetColor(Color);
MoveTo(x+i*k,y);
sa[i]:=1;
F[i]:=Sa[i];
Str(Sa[i],Elm);
OutText(Elm);
Stop:=False;
End;
'2':Begin
SetColor(7);
MoveTo(x+i*k,y);
Str(Sa[i],Elm);
OutText(Elm);
SetColor(Color);
MoveTo(x+i*k,y);
sa[i]:=0;
F[i]:=Sa[i];
Str(Sa[i],Elm);
OutText(Elm);
Stop:=False;
End;
#13:Begin Stop:=True; End;
End;
End;
Until(Stop);
SetTextStyle(0,0,1);
End;
{---------------------------------------}
{Вывод образующей матрицы}
Procedure OutPutObr_Matrix(x,y : Integer;Obr_Matr : Two_Matrix );
Var k,i,j : Integer;
Elm : String;
Begin
k:=12;
For i:=1 to _N Do
Begin
For j:=1 to _N Do
Begin
MoveTo(x+j*k,i*10+y);
Str(Obr_Matr[i,j],Elm);
OutText(Elm);
End;
End;
SetColor(4);
For i:=1 to _N Do
Begin
For j:=_N+1 to _N+_M-1 Do
Begin
MoveTo(x+j*k,i*10+y);
Str(Obr_Matr[i,j],Elm);
OutText(Elm);
End;
End;
End;
{----------------------------------}
{Вывод полученной кодовой комбинации}
Procedure OutPut(x,y : Integer;F,A : Mass1);
Var k,s : Integer;
Elm : String;
Begin
MoveTo(x+10,y-20);
Str(_N+_M-1,Elm);
OutText(Elm);
MoveTo(x+(_N+_M)*12-3,y-20);
Str(0,Elm);
OutText(Elm);
k:=12;
For i:=1 to _N Do Cicle_Kod[i]:=F[i];
s:=1;
For i:=_N+1 To _N+_M-1 Do
Begin
Cicle_Kod[i]:=A[s];
s:=s+1;
End;
For i:=1 to _N Do
Begin
MoveTo(x+i*k,y);
Str(Cicle_Kod[i],Elm);
OutText(Elm);
End;
SetColor(4);
For i:=_N+1 to _N+_M-1 Do
Begin
MoveTo(10+x+i*k,y);
Str(Cicle_Kod[i],Elm);
OutText(Elm);
End;
End;
{---------------------------------}
{выход из программы}
Function _Exit(Fon,Color : Integer;Col_Simv : Byte) : integer;
Var x,y,k : Integer;
Stop : Boolean;
Ch : Char;
Begin
Window_(250,200,450,300,1,'Выход');
x:=225;
y:=260;
k:=80;
SetTextStyle(0,0,1);
SetColor(Col_Simv);
For i:=1 to 2 do
Begin
MoveTo(x+i*k,y);
OutText(Y_No[i]);
End;
i:=1;
SetFillStyle(1,Fon);
Bar(x+i*k-30,y-15,x+i*k+30,y+15);
MoveTo(x+i*k,y);
Setcolor(Color);
OutText(Y_No[i]);
Stop:=False;
Repeat
ch:=ReadKey;
Case ch Of
#75:Begin
SetFillStyle(1,7);
Bar(x+i*k-30,y-15,x+i*k+30,y+15);
Setcolor(Col_Simv);
MoveTo(x+i*k,y);
OutText(Y_No[i]);
i:=i-1;
if(i<1)then i:=1;
SetFillStyle(1,Fon);
Bar(x+i*k-30,y-15,x+i*k+30,y+15);
SetColor(Color);
MoveTo(x+i*k,y);
OutText(Y_No[i]);
Stop:=False;
End;{влево}
#77:Begin
SetFillStyle(1,7);
Bar(x+i*k-30,y-15,x+i*k+30,y+15);
Setcolor(Col_Simv);
MoveTo(x+i*k,y);
OutText(Y_No[i]);
i:=i+1;
if(i>2)then i:=2;
SetFillStyle(1,Fon);
Bar(x+i*k-30,y-15,x+i*k+30,y+15);
SetColor(Color);