DelphiFAQ Home Search:
General :: Programming :: Delphi :: Strings
Algorithms for string handling problems, implemented in Delphi but useful for any procedural language.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Simple Encryption/ Decryption for short strings

The following routines Encrypt(), Decrypt() are suitable for passwords and similar situations.

const
   c1 = 52845;
   c2 = 22719;
 
 function Encrypt (const s: string; Key: Word) : string;
 var
   i : byte;
 begin
   Result[0] := s[0];
   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 Decrypt (const s: string; Key: Word) : string;
 var
   i : byte;
 begin 
   Result[0] := s[0]; 
   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; 
 
 

Generated 0:01:36 on Nov 21, 2017