为什么在Delphi6里提供Base64Encode函数而没有相关的解码函数。还是我没有找到,忘指教。

解决方案 »

  1.   

    你可以用indy misc面板中的Idbase64Decoder控件来完成解码.
      

  2.   

    const
      //BaseTable
      BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
    ......
    function FindInTable(CSource:char):integer;
    begin
      result:=Pos(string(CSource),BaseTable)-1;
    end;function DecodeBase64(Source:string):string;
    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;