Delphi 解密字符串函数

2020-05-26
  • 函数类型: 自定义函数

  • 函数说明:

解密字符串函数


  • 代码如下:



function DecryptString(src: String; Key: String): string; var KeyLen: Integer; KeyPos: Integer; Offset: Integer; SrcPos: Integer; SrcAsc: Integer; TmpSrcAsc: Integer; IntTemp, I: Integer; ByteArray: TBytes; begin KeyLen := Length(Key); if KeyLen = 0 then Key := 'starlin'; KeyPos := 0; Offset := System.SysUtils.StrToInt('$' + Copy(src, 1, 2)); SrcPos := 3; IntTemp := Length(src) div 2; SetLength(ByteArray, IntTemp); I := 0; repeat try SrcAsc := StrToInt('$' + Copy(src, SrcPos, 2)); except SrcAsc := StrToInt('$00'); end; if KeyPos < KeyLen Then KeyPos := KeyPos + 1 else KeyPos := 1; TmpSrcAsc := SrcAsc xor Ord(Key[KeyPos]); if TmpSrcAsc <= Offset then TmpSrcAsc := 255 + TmpSrcAsc - Offset else TmpSrcAsc := TmpSrcAsc - Offset; ByteArray[I] := TmpSrcAsc; I := I + 1; Offset := SrcAsc; SrcPos := SrcPos + 2; until SrcPos >= Length(src); Result := StringOf(ByteArray); end;



  • 用法示例:

无 



《学习大师原创文档,请勿转载,侵权必究》





阅读140