Examples Delphi

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[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[0] := s[0];
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;