function tform1.Encrypt( S: String; Key: Word): String;
var
I: Integer;
j: Integer;
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;
s:=Result;
Result:='';
for i:=1 to length(s) do
begin
j:=Integer(s[i]);
Result:=Result + Char(65+(j div 26))+Char(65+(j mod 26));
end;
end;
---------------------------------------------------
: mengxiang5160(aaa) ( ) 说的这个我以前用过,还算好使,^_^
函数是:
function tform1.Encrypt( S: String; Key: Word): String;
var
I: Integer;
j: Integer;
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;
s:=Result;
Result:='';
for i:=1 to length(s) do
begin
j:=Integer(s[i]);
Result:=Result + Char(65+(j div 26))+Char(65+(j mod 26));
end;
end;
// Another one
function TransChar(AChar: Char): Integer;
begin
if AChar in ['0'..'9'] then
Result := Ord(AChar) - Ord('0')
else
Result := 10 + Ord(AChar) - Ord('A');
end;
function StrToHex(AStr: string): string;
var
I :Integer;
Tmp: string;
begin
Result := '';
For I := 1 to Length(AStr) do
begin
Result := Result + Format('%2x', [Byte(AStr[I])]);
end;
I := Pos(' ', Result);
While I > 0 do
begin
Result[I] := '0';
I := Pos(' ', Result);
end;
end;
function HexToStr(AStr: string): string;
var
I : Integer;
CharValue: Word;
begin
Result := '';
For I := 1 to Trunc(Length(Astr)/2) do
begin
Result := Result + ' ';
CharValue := TransChar(AStr[2*I-1])*16 + TransChar(AStr[2*I]);
Result[I] := Char(CharValue);
end;
end;
function Encrypt(const S: String; Key: Word): String;
var
I : Integer;
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;
if Result[I] = Chr(0) then
Result[I] := S[I];
end;
Result := StrToHex(Result);
end;
function Decrypt(const S: String; Key: Word): String;
var
I: Integer;
S1: string;
begin
S1 := HexToStr(S);
Result := S1;
for I := 1 to Length(S1) do
begin
if char(byte(S1[I]) xor (Key shr 8)) = Chr(0) then
begin
Result[I] := S1[I];
Key := (byte(Chr(0)) + Key) * C1 + C2; //±£Ö¤KeyµÄÕýÈ·ÐÔ¡¡¡¡
end
else begin
Result[I] := char(byte(S1[I]) xor (Key shr 8));
Key := (byte(S1[I]) + Key) * C1 + C2;
end;
end;
end;
// just a simple case
function CipherPassword(userpass: string): string;
var
i: integer;
begin
result := '';
for i := 1 to length(userpass) do
begin
if (i mod 2) = 1 then
begin
result := result + char(ord(userpass[i]) xor $5A);
end
else begin
result := result + char(ord(userpass[i]) xor $3B);
end;
end;
end;