?? unit1.pas
字號:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls, ImgList, IdBaseComponent, IdComponent,
IdIPWatch;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Memo1: TMemo;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
ListBox1: TListBox;
Button2: TButton;
Memo2: TMemo;
Edit3: TEdit;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2, Unit3;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
type
data=array[0..60] of Integer;
data2=array[0..60,0..60] of Integer;
var
i,j,n,m,jinwei,l1,l2,zhongjian,l3:integer;
str,str2:string;
Gx:data2;
Mx,xx:data;
begin
l1:=length(form1.Edit1.Text);
l2:=length(form1.Edit2.Text);
l3:=l1+l2;
for i:=1 to l3-1 do
begin // 提取
//x:=form1.edit1.TBDockHeight;
//str:='whild'+'100';
//str;=string(form1.Edit1);
//showmessage('hennl');
//form1.listbox1.
//form1.listbox1.Items.Add(str);
if i<=length(form1.Edit1.Text) then //Gx付值
begin
if form1.Edit1.Text<>'' then
begin
str:=copy(form1.Edit1.Text,i,1);
if (str='0')or (str='1') then
begin
Gx[1,i]:=strtoint(copy(form1.Edit1.Text,i,1));
//str2:=str2+inttostr(Gx[1,i]);
//Str2:=str2+#13; {一行處理完成后,加上回車控制符}
end
else
begin
showmessage('請輸入 傳輸碼元Mx');
exit;
Application.ProcessMessages;
//MessageBox('This should be on top.', 'Look', mb_OK);
//break;
end
end
end
else
begin
Gx[1,i]:=0;
end;
if i<=length(form1.Edit2.Text) then //Mx復(fù)制
begin
str:=copy(form1.Edit2.Text,i,1);
if (copy(form1.Edit2.Text,1,1)='1') and (str='0')or (str='1') then
begin
Mx[i]:= strtoint (copy(form1.Edit2.Text,i,1));
end
else
begin
showmessage('請輸入 生成多項式Gx');
exit;
Application.ProcessMessages;
//MessageBox('This should be on top.', 'Look', mb_OK);
//break;
end
end;
//form1.listbox1.Items.Add(inttostr(Gx[i])); {打印}
//Memo1.lines.text:=str2;
end;
//計算//////////////////////////
for i:=1 to l2 do
Gx[2,i]:=Gx[1,i]; //g(i+l1)=0; %補齊了
i:=1;jinwei:=0;
while jinwei<=l1 do
begin
j:=1;
n:=1;
xx[1]:=0;
while j<l1+l2 do //%異或運算g(i+1,jinwei+j)=xor( g(i,jinwei+j),m(j));
begin
if j<=l2 then
begin
Gx[i+1,jinwei+j]:=Mx[j]; //%m負(fù)值
//Gx[i+2,jinwei+j]:=xor(Gx[i,jinwei+j],Mx[j]); //%異或
if Gx[i,jinwei+j]<>Mx[j] then
begin
Gx[i+2,jinwei+j]:=1;
xx[n]:=j;
n:=n+1;
end
else
begin
Gx[i+2,jinwei+j]:=0;
end
end
else
if j+jinwei<=l1 then
begin
Gx[i+2,jinwei+j]:=Gx[1,jinwei+j]; //%g負(fù)值
end;
j:=j+1;
end;
j:=1;
if xx[1]=0 then
begin
xx[1]:=l2+1;
while Gx[i+2,jinwei+j]=0 do
begin
jinwei:=jinwei+1;
end;
end
else
begin
jinwei:=jinwei+xx[1]-1;
end;
i:=i+2;
end;
///////////////////////////////
///////////打印
for i:=1 to l1+l2+1 do {利用雙循環(huán)組織數(shù)組ary2的輸出串}
Begin
j:=1; n:=1;xx[1]:=0;
{ for j:=1 to l1+l2-1 do
begin
if Gx[i,j]=1 then
begin
xx[n]:=j;
n:=n+1;
end;
if xx[1]>l1-l2 then
begin
//break; //跳出for循環(huán)
//continue;//跳出單次循環(huán)
exit; //跳出整個函數(shù)
end;
end;}
For j:=1 to l1+l2-1 do {內(nèi)循環(huán)完成一行上數(shù)據(jù)的輸出串處理}
begin
str2:=str2+inttostr(Gx[i,j]);
if Gx[i,j]=1 then
begin
xx[n]:=j;
n:=n+1;
end;
if xx[1]>l1 then
begin
//break;
if l1>l2 then
//break; //跳出for循環(huán)
//continue;//跳出單次循環(huán)
//exit; //跳出整個函數(shù)
end;
end;
form1.listbox1.Items.Add(inttostr(xx[1]));
//if (xx[1]=0) then
if (xx[1]=0) or (xx[1]>l1) then
break;
str2:=str2+#13; {一行處理完成后,加上回車控制符}
End;
str2:=str2+' 此行后'+inttostr(l2-1)+'即為校驗位';
Memo1.lines.text:=str2; {在memo1顯示ary2數(shù)組的內(nèi)容}
Showmessage(str2);
{if xx[1]>l1-l2 then
begin
break; //跳出for循環(huán)
end;}
End;
procedure TForm1.Button2Click(Sender: TObject);
type
data=array[0..40] of Integer;
data2=array[0..40,0..40] of Integer;
var
i,j,n,m,jinwei,l1,l2,zhongjian,l3:integer;
str,str2:string;
Gx:data2;
Mx,xx:data;
begin
l1:=length(form1.Edit1.Text);
l2:=length(form1.Edit2.Text);
l3:=l1+l2;
for i:=1 to l3 do
begin // 提取
//x:=form1.edit1.TBDockHeight;
//str:='whild'+'100';
//str;=string(form1.Edit1);
//showmessage('hennl');
//form1.listbox1.
//form1.listbox1.Items.Add(str);
if (i<=length(form1.Edit3.Text)) then //Gx付值
begin
if form1.Edit1.Text<>'' then
begin
str:=copy(form1.Edit3.Text,i,1);
if (length(form1.Edit3.Text)=l3-1) and ((str='0') or (str='1')) then
begin
Gx[1,i]:=strtoint(copy(form1.Edit3.Text,i,1));
//str2:=str2+inttostr(Gx[1,i]);
//Str2:=str2+#13; {一行處理完成后,加上回車控制符}
end
else
begin
showmessage('位數(shù)不對 請輸入實收數(shù)據(jù)');
exit;
Application.ProcessMessages;
//MessageBox('This should be on top.', 'Look', mb_OK);
//break;
end;
end;
end
else
begin
//showmessage(copy(form1.Edit3.Text,i,1));
{ str:=copy(form1.Edit3.Text,i,1);
if (length(form1.Edit3.Text)=length(form1.Edit2.Text)-1) and not(str='0') or (str='1') then
begin
Gx[1,i]:=strtoint(copy(form1.Edit3.Text,i-l1,1));
//str2:=str2+inttostr(Gx[1,i]);
//Str2:=str2+#13; {一行處理完成后,加上回車控制符}
{ end
else
begin
showmessage('校驗馬有誤');
exit;
//Application.ProcessMessages;
//MessageBox('This should be on top.', 'Look', mb_OK);
//break;
end }
end;
if i<=length(form1.Edit2.Text) then //Mx復(fù)制
begin
str:=copy(form1.Edit2.Text,i,1);
if (copy(form1.Edit2.Text,1,1)='1') and (str='0')or (str='1') then
begin
Mx[i]:= strtoint (copy(form1.Edit2.Text,i,1));
end
else
begin
showmessage('請輸入 生成多項式Mx');
exit;
Application.ProcessMessages;
//MessageBox('This should be on top.', 'Look', mb_OK);
//break;
end
end;
//form1.listbox1.Items.Add(inttostr(Gx[i])); {打印}
//Memo1.lines.text:=str2;
end;
//計算//////////////////////////
for i:=1 to l2 do
Gx[2,i]:=Gx[1,i]; //g(i+l1)=0; %補齊了
i:=1;jinwei:=0;
while jinwei<=l1 do
begin
j:=1;
n:=1;
xx[1]:=0;
while j<l1+l2 do //%異或運算g(i+1,jinwei+j)=xor( g(i,jinwei+j),m(j));
begin
if j<=l2 then
begin
Gx[i+1,jinwei+j]:=Mx[j]; //%m負(fù)值
//Gx[i+2,jinwei+j]:=xor(Gx[i,jinwei+j],Mx[j]); //%異或
if Gx[i,jinwei+j]<>Mx[j] then
begin
Gx[i+2,jinwei+j]:=1;
xx[n]:=j;
n:=n+1;
end
else
begin
Gx[i+2,jinwei+j]:=0;
end
end
else
if j+jinwei<=l3 then
begin
Gx[i+2,jinwei+j]:=Gx[1,jinwei+j]; //%g負(fù)值
end;
j:=j+1;
end;
j:=1;
if xx[1]=0 then
begin
xx[1]:=l2+1;
while Gx[i+2,jinwei+j]=0 do
begin
jinwei:=jinwei+1;
end;
end
else
begin
jinwei:=jinwei+xx[1]-1;
end;
i:=i+2;
end;
///////////////////////////////
///////////打印
for i:=1 to l1+l2+2 do {利用雙循環(huán)組織數(shù)組ary2的輸出串}
Begin
j:=1;xx[1]:=0;n:=1;
{ for j:=1 to l1+l2-1 do
begin
if Gx[i,j]=1 then
begin
xx[n]:=j;
n:=n+1;
end;
if xx[1]>l1-l2 then
begin
//break; //跳出for循環(huán)
//continue;//跳出單次循環(huán)
exit; //跳出整個函數(shù)
end;
end;}
For j:=1 to l1+l2-1 do {內(nèi)循環(huán)完成一行上數(shù)據(jù)的輸出串處理}
begin
str2:=str2+inttostr(Gx[i,j]);
if Gx[i-1,j]<>Gx[i-2,j] then
begin
xx[n]:=j;
n:=n+1;
//break;
end
else
xx[l1+l2]:=xx[l1+l2]+1;
if xx[1]>l1 then
begin
//break;
if l1>l2 then
//break; //跳出for循環(huán)
//continue;//跳出單次循環(huán)
//exit; //跳出整個函數(shù)
end;
end;
form1.listbox1.Items.Add(inttostr(xx[l1+l2]));
//if (xx[1]=0) then
if xx[l1+l2]=l1+l2-1 then
break;
if (xx[1]>l1) then
break;
;str2:=str2+#13; {一行處理完成后,加上回車控制符}
xx[l1+l2]:=0;
End;
str2:=str2+' 此行若為0,則校驗成功,數(shù)據(jù)傳輸沒出錯' ;
Memo2.lines.text:=str2; {在memo1顯示ary2數(shù)組的內(nèi)容}
Showmessage(str2);
{if xx[1]>l1-l2 then
begin
break; //跳出for循環(huán)
end;}
End;
procedure TForm1.Button3Click(Sender: TObject);
begin
Form2.Show;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
Form1.close;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Form3.Show;
end;
end.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -