短字符串的简单加密/解密 (2001年7月12日)
本站更新 分类:算法 作者: 推荐: 阅读次数:589
(http://www.tommstudio.com)
--------------------------------------------------------------------------------
The following routines Encrypt(), Decrypt() are suitable for passwords and similar situations.
const
c1 = 52845;
c2 = 22719;
function Encrypt (const s: string; Key: Word) : string;
var
i : byte;
begin
Result[0] := s[0];
for i := 1 to length (s) do
begin
Result := Char (byte (s) xor (Key shr 8));
Key := (byte (Result) + Key) * c1 + c2
end
end;
function Decrypt (const s: string; Key: Word) : string;
var
i : byte;
begin
Result[0] := s[0];
for i := 1 to length (s) do
begin
Result := Char (byte (s) xor (Key shr 8));
Key := (byte (s) + Key) * c1 + c2
end
end;