Mega Search
23.2 Million


Sign Up

Make a donation  
Simple Encrypt/Decrypt with an issue  
News Group: embarcadero.public.delphi.language.delphi.general

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}

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 23-Jan-2015, at 8:35 AM EST
From: brent shelton