网上有很多这种加密解密函数,都差不多,整理两个,以后方便使用。
const {常量}
XorKey: array[0..7] of Byte = ($B2, $11, $AB, $35, $63, $6D, $48, {1}9); //字符串加密用,可以自己改
//两种差不多,使用重载。
function EncStrX(ASource: pansichar): string; overload; //加密
function DecStrX(ASource: pansichar): string; overload; //解密
function EncStrX(ASource: string): string; overload; //加密
function DecStrX(ASource: string): string; overload; //解密
function EncStrX(ASource: pansichar): string; //加密
var
j: Integer;
cTemp: Char;
str, sResult: string;
begin
j := 0;
str := string(ASource);
for cTemp in str do
begin
sResult := sResult + IntToHex(Byte(cTemp) xor XorKey[j], 2);
j := (j + 1) mod 8; //取余
end;
result := pchar(sResult);
end;
function DecStrX(ASource: pansichar): string; //解密
var
i, j: Integer;
str, sResult: string;
begin
str := string(ASource);
j := 0;
for i := 1 to Length(Str) div 2 do
begin
sResult := sResult + Char(StrToInt('$' + Copy(Str, i * 2 - 1, 2)) xor XorKey[j]);
j := (j + 1) mod 8;
end;
result := pchar(sResult);
end;
function EncStrX(ASource: string): string; //加密 這是用的一個異或加密
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(ASource) do
begin
Result:=Result+IntToHex(Byte(ASource[i]) xor XorKey[j],2);
j:=(j+1) mod 8;
end;
end;
function DecStrX(ASource: string): string;
var
i,j:Integer;
begin
Result:='';
j:=0;
for i:=1 to Length(ASource) div 2 do
begin
Result:=Result+Char(StrToInt('$'+Copy(ASource,i*2-1,2)) xor XorKey[j]);
j:=(j+1) mod 8;
end;
end;