字符串加解密例子

来源:互联网 发布:c语言迷宫程序 编辑:程序博客网 时间:2024/05/18 17:55
function Enc1(const Str: string): string;
var
   i, j: integer;
begin
   SetLength(Result, Length(Str) * 2);
 
   j := 0;
   for i := 0 to Length(Str) * sizeof(char) - 1 do
   begin
      PByte(Result)[i * 2] := (PByte(Str)[i] xor XorKey1[j]) shr 4 48;
      PByte(Result)[i * 2 1] := (PByte(Str)[i] xor XorKey1[j]) and 15 48;
      j := (j + 1mod 8;
   end;
end;
  
function Dec1(const Str: string): string;
var
  i, j: integer;
begin
  SetLength(Result, Length(Str) div 2);
 
  j := 0;
  for i := 0 to Length(Result) * sizeof(char) - 1 do
  begin
    PByte(Result)[i] := ((PByte(Str)[i * 2] - 48shl 4 +
                         (PByte(Str)[i * 2 1] - 48and 15xor XorKey1[j];
    j := (j + 1mod 8;
  end;
end;
原创粉丝点击