Unit uencrypt_decrypt; interface uses Sysutils; const xorkey:array[0..7] of Byte = ($B 2, $09, $AA, $55, $9 3, $6d, $84, $47); //through key key encryption function encryptstring (source, key:string): String;function unencryptstring (source , key:string): string; //XOR/Cryptographic function Enc (str:string): String;function Dec (str:string): string; Implementation function encryptstring (Source, key:string): string;var Keylen,keypos,offset,srcpos, srcasc,range:integer; dest:string;begin Keylen: = Length (Key); If Keylen = 0 then Key: = ' Delphi '; keypos: = 0; Range: = 256; randomize; Offset: = Random (Range); Dest: = Format ('%1 '). 2x ', [Offset]); for Srcpos: = 1 to Length (Source) do begin SRCASC: = (Ord (Source[srcpos]) + OFFSE T) mod 255; If Keypos < Keylen then Keypos: = Keypos + 1 else   ; Keypos: = 1; SRCASC: = SrCAsc xor Ord (Key[keypos]); Dest: = Dest + Format ('%1.2x ', [SRCASC]); Offset: = srcasc; End ; Result: = Dest;end; function unencryptstring (Source, key:string): string;var Keylen,keypos,offset, srcpos,srcasc,tmpsrcasc:integer; dest:string;begin Keylen: = Length (Key); If Keylen = 0 then &nb Sp Key: = ' Delphi '; keypos: = 0; Offset: = Strtoint (' $ ' + copy (Source, 1, 2)); Srcpos: = 3; repeat&nb Sp SRCASC: = Strtoint (' $ ' + copy (Source, Srcpos, 2)); If Keypos < Keylen then KEYP OS: = Keypos + 1 else Keypos: = 1; TMPSRCASC: = Srcasc xor Ord (Key[keypos]); If TMPSRCASC <= Offset then TMPSRCASC: = 255 + tmpsrcasc-offset ELSE&N Bsp TMPSRCASC: = tmpsrcasc-offset; Dest: = Dest + chr (TMPSRCASC); Offset: = srcasc;& nbsp SrCPos: = Srcpos + 2; until srcpos >= Length (Source); Result: = Dest;end; function Enc (str: String): string;var I, j:integer;begin Result: = '; J: = 0; for I: = 1 to Length (str) do begin Result: = result + Inttohex (Byte (Str[i]) xor Xorkey[j], 2); J: = (j + 1) mod 8; end; End; function Dec (str:string): string;var i, j:integer;begin Result: = '; J: = 0; for I: = 1 to Length (str) div 2 do begin Result: = result + Char (strtoint (' $ ' + Copy (str, I * 2-1, 2)) XOR&NB Sp XORKEY[J]); J: = (j + 1) mod 8; end;end; end. ====================================== ======-based DES encryption and decryption: http://blog.csdn.net/warrially/article/details/8089041
Delphi String Encryption/decryption