I'm using this in a Delphi 7 project. This seems to work ok but not when encrypting S when it begins with 1C
S := '1Cabcdefg';
Any fix without breaking existing strings that have been encrypted with this code?
Thanks!
{code}
function EncryptStr(const S: String; Key: Word): String;
var
I: Integer;
const
C1 = 53761;
C2 = 32618;
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;
end;
function DecryptStr(const S: String; Key: Word): String;
var
I: Integer;
const
C1 = 53761;
C2 = 32618;
begin
Result := S;
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;
{code}