Delphi 加密字符串函数

  • 函数类型: 自定义函数

  • 函数说明:

加密字符串函数


  • 代码如下:



 function EncryptString(src: String; Key: String): string;
var
  KeyLen: Integer;
  KeyPos: Integer;
  Offset: Integer;
  dest: String;
  SrcPos: Integer;
  SrcAsc: Integer;
  Range: Integer;
  IntTemp: Integer;
  SrcAnsi: PAnsiChar;
begin
  KeyLen := Length(Key);
  KeyPos := 0;
  Range := 1;
  Randomize;
  Offset := Random(Range);
  dest := Format('%1.2x', [Offset]);
  SrcAnsi := PAnsiChar(AnsiString(src));
  IntTemp := Length(SrcAnsi);
  for SrcPos := 1 to IntTemp do
  begin
    SrcAsc := (Ord(SrcAnsi[SrcPos - 1]) + Offset) 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;



  • 用法示例:

无 



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





联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678