【转载】牛人用批处理写的Base64编解码程序

这是一个使用批处理语言编写的Base64编码解码程序,支持对文件进行Base64编码和解码,最大支持64KB的文件。程序通过Debug命令行工具实现,包括编码和解码两个部分,并提供了帮助信息。
摘要由CSDN通过智能技术生成

太牛了!

估计应该没多少Bug。谁能优化它?


 

 :: Base64.cmd Beta -- Base64 编码解码 01/28/2007 By 0401
@echo off
setlocal enabledelayedexpansion
set op=
set Key=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
set hexstr=0 1 2 3 4 5 6 7 8 9 A B C D E F
set d=0
for %%i in (%hexstr%) do set d!d!=%%i&set/a d+=1
if "%~1"=="" goto :help
if "%~1"=="/?" goto :help
for %%i in (d D e E h H) do (
        if "%~1"=="/%%i" call :arg%%i %*
        if exist "%~1" (
                if exist "%~1/" set error=Sorry,不支持对一个目录进行 Base64 编码。& goto :error
                set op=encode
                set infile=%~sf1
        )
)
if defined error goto :error
if defined op goto :%op%
set error=无效的参数或文件名:%1。& goto :error

:arge
set op=encode
:argd
if not defined op set op=decode
set infile=%~sf2
if not defined infile set error=没有指定输入文件。& exit/b
if not exist "%infile%" set error=找不到指定文件:%infile%。& exit/b
set outfile=%~f3
goto :eof
:argh
set op=help
goto :eof
:error
echo %error%
exit/b

goto :encode
s 文件大小
l 文件加上100H f子命令填充内存的长度。
c 只用来计算第一次编码的时间
k 判断 c1 c2 c3
w 每行生成几组4个字节的编码字符,默认18
q 判断等于w时输出一行编码字符串
n 用来过滤掉重复的字节
:encode
>nul (chcp 437&graftabl 936)
cls
for %%i in (%infile%) do set s=%%~zi
if %s% equ 0 exit/b
if %s% gtr 65535 set error=编码失败,文件大小上限为 64KB。& goto :error
set/p=编码初始化中,请稍等。<nul
set of=B64ENC
set/p=<nul>"%~dp0%of%"
set/a l=s+255
call :d2h %l%
set l=%hex%
call :d2h %s%

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值