//前面定义好常量
const
C1 = 123456;
C2 = 234567;
PASSKEY = '66666';
//加密函数
function Encrypt(const S: String; Key: Word): String;
var
I: byte;
begin
Result:=S;
for I:= 1 to Length(S) do begin
Result[I]:= char(byte(S[I]) xor (Key shr 8));
Key:=(byte(Result[I]) + Key) * C1 + C2;
end;
end;
//解密函数
function Decrypt(const S: String; Key: Word): String;
var
I: byte;
begin
Result:=S;
for I := 1 to Length(S) do begin
Result[I]:= char(byte(S[I]) xor (Key shr 8));
Key := (byte(S[I]) + Key) * C1 + C2;
end;
end;
//使用方法------------------------------------------------
tmp := Encrypt('需要加密的内容', StrToInt(PASSKEY));
tmp := Decrypt('需要解密的内容', StrToInt(PASSKEY));
const
C1 = 123456;
C2 = 234567;
PASSKEY = '66666';
//加密函数
function Encrypt(const S: String; Key: Word): String;
var
I: byte;
begin
Result:=S;
for I:= 1 to Length(S) do begin
Result[I]:= char(byte(S[I]) xor (Key shr 8));
Key:=(byte(Result[I]) + Key) * C1 + C2;
end;
end;
//解密函数
function Decrypt(const S: String; Key: Word): String;
var
I: byte;
begin
Result:=S;
for I := 1 to Length(S) do begin
Result[I]:= char(byte(S[I]) xor (Key shr 8));
Key := (byte(S[I]) + Key) * C1 + C2;
end;
end;
//使用方法------------------------------------------------
tmp := Encrypt('需要加密的内容', StrToInt(PASSKEY));
tmp := Decrypt('需要解密的内容', StrToInt(PASSKEY));