Function Encrypt(Str1:String):String;
//加密程序
var
RandomValue,X:Byte;
Str2:String;
i:Integer;
begin
RandSeed:=12345;
for i:=1 to Length(Str1) do
begin
RandomValue:=Random(255);
x:=Ord(Str1[i]) XOR Random(256);
Str2:=Str2 + Chr(x);
end;
Result:=Str2;
end;
Function Decrypt(Str1:String):String;
//解密程序,和加密程序差不多,采用random值是伪随机,
//如果指定RandomSeed,则Random的开始规律是一致的原理
var
RandomValue,X:Byte;
Str2:String;
i:Integer;
begin
RandSeed:=12345;
for i:=1 to Length(Str1) do
begin
RandomValue:=Random(255);
x:=Ord(Str1[i]) XOR Random(256);
Str2:=Str2 + Chr(x);
end;
Result:=Str2;
end;
Function Encrypt(Const S: String): String;
Function Decrypt(Const S: String): String;
Implementation
Uses Sysutils;
Function Encrypt(Const S: String): String;
Var
I, key: Integer;
M: Byte;
str: String;
Begin
key := kk;
For I := 1 To Length(S) Do
Begin
M := byte(S[I]) Xor (Key Shr 4);
Key := (M + Key) * C1 + C2;
str := Format('%2x', [M]);
If str[1] = ' ' Then
str[1] := '0';
Result := Result + str;
End;
End;
Function Decrypt(Const S: String): String;
Var
I, key: Integer;
M: Byte;
Begin
key := kk;
For I := 1 To Length(S) Div 2 Do
Begin
M := strToInt('x' + copy(s, I * 2 - 1, 2));
Result := Result + char(M Xor (Key Shr 4));
Key := (M + Key) * C1 + C2;
End;
End;