Function to encrypt/decrypt strings  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 13/02/00

Tip accessed 1017 times

 


They are two very simple functions, but that at least they avoid the one that you/they change you texts *iin your executable one playing the .EXE with a hexadecimal editor.


  const
     {C1 y C2 are used for encryption of Master Password string}
     {C1 y C2 aon usadas para encriptar la cadena de la clave}
          C1 = 52845;
          C2 = 11719;


       { Standard Decryption algorithm - Copied from Borland}
       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) * C1 + C2;
         end;
       end;

       { Standard Encryption algorithm - Copied from Borland}
       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) * C1 + C2;
         end;
       end;




For example, to encrypt the caption of Label1:


 	Label1.Caption:= Encrypt(Label1.Caption,6474);



To decrypt it:


 	Label1.Caption:= Decrypt(Label1.Caption,6474);





Updated at 08/10/99



An modification of the prior functions, that use a pseudo ramdom key:


 function Encript(aFrase: String, aClave: Integer): String;
 begin
    Result:='';
    RandSeed:=aClave;
    For aa:=1 to Length(aFrase) do
        Result:=Result+Chr(Byte(aFrase[aa]) xor random(256));
 end;

 function Decript(aFrase: String; aClave: Integer): String;
 begin
    Result:='';
    RandSeed:=aClave;
    For aa:=1 to Length(aFrase) do
        Result:=Result+Chr(Byte(aFrase[aa]) xor random(256));
 end;



Updated at 17/10/99
Added the functions send by Abrasax


Updated at 13/02/2000