Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Simple Encrypt/Decrypt with an issue


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Jan 28, 2015 11:31 AM Last Post By: brent shelton
brent shelton

Posts: 29
Registered: 2/14/09
Simple Encrypt/Decrypt with an issue  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2015 8:35 AM
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!

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;
brent shelton

Posts: 29
Registered: 2/14/09
Re: Simple Encrypt/Decrypt with an issue  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 28, 2015 11:31 AM   in response to: brent shelton in response to: brent shelton
Got someone on oDesk to help me.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02