本帖最后由 plp626 于 2012-3-2 23:17 编辑
ascii 转 base64编码- @ECHO off
- :: base64_d.cmd version 1.0
- :: ascii文件(字符串) 转 base64编码存储
- :: 用法:第一个参数为文件名,或字符串,建议第一个参数用双引号引起来;
- :: 若当期路径没有%1文件名, 则%1被当做字符串处理;
- :: 程序依赖ascii转hex的外部程序hex.cmd(version 1.1即可),下载地址:
- :: http://www.bathome.net/thread-12688-1-1.html
-
- setlocal enabledelayedexpansion
- set "str="
- for /f "tokens=1-3" %%a in ('hex.cmd "%~1" 3')do (
- if %%b%%c.==. (
- call:ascii2base64 0x%%a -1 -1 ans
- )else if %%c.==. (
- call:ascii2base64 0x%%a 0x%%b -1 ans
- )else (
- call:ascii2base64 0x%%a 0x%%b 0x%%c ans
- )
- set/p=!ans!<nul
- )
- goto:eof
-
- :ascii2base64 <int> <int> <int> <ret> //code by plp;
- setlocal&Set/a a1=%1,a2=%2,a3=%3
- set/a "b1=a1/4,b2=a1%%4<<4|a2/16,b3=(a2%%16<<2|a3/64)-3*(a2>>31),b4=a3%%64"
- Set s=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
- Set $=&Set $=!s:~%b1%,1!!s:~%b2%,1!!s:~%b3%,1!!s:~%b4%,1!
- endlocal&Set %4=%$%&goto:eof
复制代码
|