const
  cKey1 = 52845;
  cKey2 = 22719;//Encrypt a string
function Encrypt(const S: string; Key: Word): string;
var
I: byte;
begin
  SetLength(result,length(s));
  for I := 1 to Length(S) do
    begin
      Result[I] := char(byte(S[I]) xor (Key shr 8));
      Key := (byte(Result[I]) + Key) * cKey1 + cKey2;
    end;
end;//Decrypt a string encoded with Encrypt
function Decrypt(const S: string; Key: Word): string;
var
  I: byte;
begin
  SetLength(result,length(s));
  for I := 1 to Length(S) do
    begin
      Result[I] := char(byte(S[I]) xor (Key shr 8));
      Key := (byte(S[I]) + Key) * cKey1 + cKey2;
    end;
end;