来自:creation-zy, 时间:2002-10-6 18:18:00, ID:1361586
const
XorKey:array[0..7] of Byte=($B2,$09,$AA,$55,$93,$6D,$84,$47);
function Enc(Str:String):String;
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) do
begin
Result:=Result+IntToHex(Byte(Str) xor XorKey[j],2);
j:=(j+1) mod 8;
end;
end;
function Dec(Str:String):String;
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) div 2 do
begin
Result:=Result+Char(StrToInt('$'+Copy(Str,i*2-1,2)) xor XorKey[j]);
j:=(j+1) mod 8;
end;
end;
procedure TForm1.Button1Click(Sender: TObject); //加密
begin
Edit2.Text:=Enc(Edit1.Text);
end;
procedure TForm1.Button2Click(Sender: TObject); //解密
begin
Edit3.Text:=Dec(Edit2.Text);
end;