
//------------------------------------------
function Enc(Str:String):String;{加密}
function Dec(Str:String):String;{解密}
//------------------------------------------
//------------------------------------------
{字符加密}
//调用 Edit1.Text:=Enc(Edit1.Text);//加密
function Enc(Str:String):String;
const XorKey:array[0..7] of Byte=($B2,$09,$AA,$55,$93,$6D,$84,$47);
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) do
begin
Result:=Result+IntToHex(Byte(Str[i]) xor XorKey[j],2);
j:=(j+1) mod 8;
end;
end;
{字符解密}
//调用 Edit2.Text:=Dec(Edit1.Text);//解密
function Dec(Str:String):String;
const XorKey:array[0..7] of Byte=($B2,$09,$AA,$55,$93,$6D,$84,$47);
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;
//调用 Edit1.Text:=Enc(Edit1.Text);//加密
function Enc(Str:String):String;
const XorKey:array[0..7] of Byte=($B2,$09,$AA,$55,$93,$6D,$84,$47);
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(Str) do
begin
Result:=Result+IntToHex(Byte(Str[i]) xor XorKey[j],2);
j:=(j+1) mod 8;
end;
end;
{字符解密}
//调用 Edit2.Text:=Dec(Edit1.Text);//解密
function Dec(Str:String):String;
const XorKey:array[0..7] of Byte=($B2,$09,$AA,$55,$93,$6D,$84,$47);
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;