中国程序员联盟 正在重新改版中ing 不便之处还请见谅 改版后将内容涉及java delphi .net php
 
  首页 | 数据库开发 | 网络通讯 | 多线程 | 多媒体开发 | 图像处理 | 程序人生 | 系统函数 | 控件开发 | Web服务
 
  当前位置:笨鱼delphi技术网>网络通讯>文章内容

delphi Base64编码转换

来源:网络 关于:轶名 发布时间:2007-06-29   [收藏] [推荐]
{ Decode base-64 files, Arne de Bruijn, 1996, Released to the Public Domain }
{ Strip everything but the base-64 lines before feeding it into this program }
uses dos;
var
 Base64:array[43..122] of byte;
var
 T:text;
 Chars:set of char;
 S:string;
 K,I,J:word;
 Buf:pointer;
 DShift:integer;
 F:file;
 B,B1:byte;
 Decode:array[0..63] of byte;
 Shift2:byte;
 Size,W:word;
begin
 FillChar(Base64,SizeOf(Base64),255);
 J:=0;
 for I:=65 to 90 do
  begin
   Base64[I]:=J;
   Inc(J);
  end;
 for I:=97 to 122 do
  begin
   Base64[I]:=J;
   Inc(J);
  end;
 for I:=48 to 57 do
  begin
   Base64[I]:=J;
   Inc(J);
  end;
 Base64[43]:=J; Inc(J);
 Base64[47]:=J; Inc(J);
 if ParamCount=0 then
  begin
   WriteLn('UNBASE64 <mime file> [<output file>]');
   Halt(1);
  end;
 S:=ParamStr(1);
 assign(T,S);
 GetMem(Buf,32768);
 SetTextBuf(T,Buf^,32768);
 {$I-} reset(T); {$I+}
 if IOResult<>0 then
  begin
   WriteLn('Error reading ',S);
   Halt(1);
  end;
 if ParamCount>=2 then
  S:=ParamStr(2)
 else
  begin write('Destination:'); ReadLn(S); end;
 assign(F,S);
 {$I-} rewrite(F,1); {$I+}
 if IOResult<>0 then
  begin
   WriteLn('Error creating ',S);
   Halt(1);
  end;
 while not eof(T) do
  begin
   ReadLn(T,S);
   if (S<>'') and (pos(' ',S)=0) and (S[1]>=#43) and (S[1]<=#122) and
    (Base64[byte(S[1])]<>255) then
    begin
     FillChar(Decode,SizeOf(Decode),0);
     DShift:=0;
     J:=0; Shift2:=1;
     Size:=255;
     B:=0;
     for I:=1 to Length(S) do
      begin
       case S[I] of
        #43..#122:B1:=Base64[Ord(S[I])];
       else
        B1:=255;
       end;
       if B1=255 then
        if S[I]='=' then
         begin
          B1:=0; if Size=255 then Size:=J;
         end
        else
         WriteLn('Char error:',S[I],' (',Ord(S[I]),')');
       if DShift and 7=0 then
        begin
         Decode[J]:=byte(B1 shl 2);
         DShift:=2;
        end
       else
        begin
         Decode[J]:=Decode[J] or Hi(word(B1) shl (DShift+2));
         Decode[J+1]:=Lo(word(B1) shl (DShift+2));
         Inc(J);
         Inc(DShift,2);
        end;
      end;
     if Size=255 then Size:=J;
     BlockWrite(F,Decode,Size);
    end;
  end;
 Close(F);
 close(T);
end.

[浏览: 次]   
上一篇:delphi 网络映射驱动器   下一篇:delphi 利用“侦听-转发”程序破译网管协议
[收藏] [推荐] [返回顶部] [打印本页] [关闭窗口]  
    评论加载中…
google adsense热点文章
·delphi 学习WinSocket的编程
·delphi 用Delphi实现远程控制
·delphi 木马DIY
·delphi Delphi实现UDP广播
·delphi 检测计算机的 Internet 连接状
·delphi 获取BIOS信息
·delphi 发送raw IP类型的数据包
·delphi 使用ftp控件下载目录
·delphi 获取IP地址以及全部TCPIP连接的
·delphi 监测TCP IP协议是否安装了
·delphi 编写上网计费软件
·delphi Modem的指令
     delphi技术网 | firefox 下载 | Avant Browser下载 | dedecms 技术网 | drupal 爱好者 | php 技术网
  Copyright@www.delphichm.com,2006-2009.All Rights Reserved.
 
程序员联盟 | delphi Java .net|QQ:707102932