主界面可以让客户定制,所以维护了一个主界面信息的表,不想放在数据库里,所以用文本文件放在客户端,但不想让用户看到,需要进行转换(二进制或16进制),请指教

解决方案 »

  1.   

    function EnCrypt( Source : String; Key : String = 'LW549' ) : String;
    //549@17:12 2003-10-23
    var
      Current : Integer;
      KeyLength : Integer;
    begin
      if Key = '' then begin
        Result := Source;
        Exit;
      end;
      KeyLength := Length( Key );
      for Current := 1 to Length( Source ) do begin
        Source[Current] := Char( Ord( Source[Current] ) xor Ord( Key[ (Current mod KeyLength) + 1 ] ) );
        Result := Result + IntToHex( StrToInt64(vartostr(Ord( Source[Current] ))), 2);
      end;
      SetLength( Result, Length( Source ) * 2 );
    end;function DeCrypt( Source : String; Key : String = 'LW549' ) : String;
    //549@17:12 2003-10-23
    var
      Current : Integer;
      KeyLength : Integer;
    begin
      if Key = '' then begin
        Result := Source;
        Exit;
      end;
      KeyLength := Length( Key );
      SetLength(Result,Length(Source) div 2);
      for Current := 1 to (Length( Source ) div 2) do begin
        Result[Current] := Char( HexToInt(Source[ Current * 2 - 1]) * 16 + HexToInt(Source[ Current * 2 ]));
        Result[Current] := Char( Ord( Result[Current] ) xor Ord( Key[ (Current mod KeyLength) + 1 ] ) );
      end;
    end;
    function HexToInt( Hex : Char ) : Integer;
    //17:12 2003-10-23
    begin
    //
      case Hex of
      '0' : Result := 0;
      '1' : Result := 1;
      '2' : Result := 2;
      '3' : Result := 3;
      '4' : Result := 4;
      '5' : Result := 5;
      '6' : Result := 6;
      '7' : Result := 7;
      '8' : Result := 8;
      '9' : Result := 9;
      'a','A' : Result := 10;
      'b','B' : Result := 11;
      'c','C' : Result := 12;
      'd','D' : Result := 13;
      'e','E' : Result := 14;
      'f','F' : Result := 15;
      else
        Result := 0;
      end;
    end;
      

  2.   

    第一楼用的方法好象可以对抗概率分析,但是毕竟叠代次数太少。
    如果用现成的,BlowFish不错,强度适中,速度也快。
      

  3.   

    一般情况下,用BASE64编码就足够了
      base64编码    
        
    const BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';function FindInTable(CSource:char):integer;
    begin
    result:=Pos(string(CSource),BaseTable)-1;
    end;
    ////
    function DecodeBase64(Source:string):string; //base64 编码
    var
    SrcLen,Times,i:integer;
    x1,x2,x3,x4,xt:byte;
    begin
    result:='';
    SrcLen:=Length(Source);
    Times:=SrcLen div 4;
    for i:=0 to Times-1 do
    begin
    x1:=FindInTable(Source[1+i*4]);
    x2:=FindInTable(Source[2+i*4]);
    x3:=FindInTable(Source[3+i*4]);
    x4:=FindInTable(Source[4+i*4]);
    x1:=x1 shl 2;
    xt:=x2 shr 4;
    x1:=x1 or xt;
    x2:=x2 shl 4;
    result:=result+chr(x1);
    if x3= 64 then break;
    xt:=x3 shr 2;
    x2:=x2 or xt;
    x3:=x3 shl 6;
    result:=result+chr(x2);
    if x4=64 then break;
    x3:=x3 or x4;
    result:=result+chr(x3);
    end;
    end;
    /////
    function EncodeBase64(Source:string):string; //base64 解码
    var
    Times,LenSrc,i:integer;
    x1,x2,x3,x4:char;
    xt:byte;
    begin
    result:='';
    LenSrc:=length(Source);
    if LenSrc mod 3 =0 then Times:=LenSrc div 3
    else Times:=LenSrc div 3 + 1;
    for i:=0 to times-1 do
    begin
    if LenSrc >= (3+i*3) then
    begin
    x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
    xt:=(ord(Source[1+i*3]) shl 4) and 48;
    xt:=xt or (ord(Source[2+i*3]) shr 4);
    x2:=BaseTable[xt+1];
    xt:=(Ord(Source[2+i*3]) shl 2) and 60;
    xt:=xt or (ord(Source[3+i*3]) shr 6);
    x3:=BaseTable[xt+1];
    xt:=(ord(Source[3+i*3]) and 63);
    x4:=BaseTable[xt+1];
    end
    else if LenSrc>=(2+i*3) then
    begin
    x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
    xt:=(ord(Source[1+i*3]) shl 4) and 48;
    xt:=xt or (ord(Source[2+i*3]) shr 4);
    x2:=BaseTable[xt+1];
    xt:=(ord(Source[2+i*3]) shl 2) and 60;
    x3:=BaseTable[xt+1];
    x4:='=';
    end else
    begin
    x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
    xt:=(ord(Source[1+i*3]) shl 4) and 48;
    x2:=BaseTable[xt+1];
    x3:='=';
    x4:='=';
    end;
    result:=result+x1+x2+x3+x4;
    end;
    end;
      

  4.   

    还是使用DES,IDEA这种够强度的加密算法吧
      

  5.   

    看到过很多加密代码,不过没注意有没有好的,大家推荐推荐,
    至少要满足以下几点:1、变长加密,如a可以加密为jasdo34758&*(^
    2、两次加密,结果不应相同。
    3、支持双字节字符