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)]);
end;
I := Pos(' ', Result);
While I <> 0 do
begin
Result := '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 := 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 := char(byte(S) xor (Key shr 8));
Key := (byte(Result) + Key) * 11 + 12;
if Result = Chr(0) then
Result := S;
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) xor (Key shr 8)) = Chr(0) then
begin
Result := S1;
Key := (byte(Chr(0)) + Key) * 11 + 12
//±&pound;&Ouml;¤Key&micro;&Auml;&Otilde;&yacute;&Egrave;·&ETH;&Ocirc;
end
else
begin
Result := char(byte(S1) xor (Key shr 8));
Key := (byte(S1) + Key) * 11 + 12;
end;
end;
end;