想对一些UniCode字符串进行加密和解密方法,
我的思路是比如:我是中国人Abs ,UniCode编码为 6211662F4E2D56FD4EBA004100620073, 然后对其进行加密,解密.  请求高手指教, 谢谢

解决方案 »

  1.   

    给你一个我常用的加密、解密方法:
    const
      sBase64: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=!';//------------------------------------------------------------------------------
    // 按源串,和编码表进行BASE64编码
    // 顺序为:3个字节折成4个字节,得数不大于64,查表得字符
    //------------------------------------------------------------------------------function Encode64(sc, table: string): string;
    var a, b, c: byte;
      s1, s2, s3, s4: byte;
      i: Integer;
    begin
      result := '';
      case length(sc) mod 3 of
        1: sc := sc + '  '; //2个空格,凑足3的倍数
        2: sc := sc + ' '; //1个空格,凑足3的倍数
      end;
      for i := 0 to (length(sc) div 3 - 1) do begin
        a := ord(sc[i * 3 + 1]);
        b := ord(sc[i * 3 + 2]);
        c := ord(sc[i * 3 + 3]);
        asm
      push eax  mov ah,a
      shr ah,2//dfaf
      mov s1,ah  mov ah,a
      mov al,b
      and ah,$03
      shl ah,4
      shr al,4
      or ah,al
      mov s2,ah  mov ah,b
      mov al,c
      and ah,$0f
      shl ah,2
      shr al,6
      or ah,al
      mov s3,ah  mov ah,c
      and ah,$3f
      mov s4,ah  pop eax
        end;
        result := result + table[s1 + 1] + table[s2 + 1] + table[s3 + 1] + table[s4 + 1];
      end;
    end;//------------------------------------------------------------------------------
    // 按源串,和编码表进行BASE64解码
    //------------------------------------------------------------------------------function Decode64(sc, table: string): string;
    var a, b, c: byte;
      s1, s2, s3, s4: byte;
      i: Integer;
    begin
      result := '';
      if Length(sc) mod 4 = 0 then
        for i := 0 to (Length(sc) div 4 - 1) do
        begin
          s1 := AnsiPos(sc[i * 4 + 1], table) - 1;
          s2 := AnsiPos(sc[i * 4 + 2], table) - 1;
          s3 := AnsiPos(sc[i * 4 + 3], table) - 1;
          s4 := AnsiPos(sc[i * 4 + 4], table) - 1; //加密时 值+1 查表,解密时查表值 -1
          asm
      push eax  mov ah,s1
      mov al,s2
      shl ah,2
      shr al,4
      or ah,al
      mov a,ah  mov ah,s2
      mov al,s3
      shl ah,4
      shr al,2
      and al,$0f
      or ah,al
      mov b,ah  mov ah,s3
      mov al,s4
      shl ah,6
      or ah,al
      mov c,ah  pop eax
          end;
          result := result + Chr(a) + Chr(b) + Chr(c);
        end;
      result := Trim(result);
    end;{
    调用方法:
    Encode64(S, sBase64) //S为待加密字符串
    Decode64(S, sBase64) //S这待解密字符串
    }
      

  2.   

    在我的blog当中有一个DES加密和解密算法,使用之即可.