|
s11ss
银牌会员
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『楼 主』:
[原创]------------Base64解密------------
@echo off
::::::::Base64 Decode {s11ss 2007-12-3}::::::::
setlocal enabledelayedexpansion
echo 请输入要转换的base64编码:
set/p es=
set "base64=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
set/a i=0
:base64-hex
set "o=!es:~%i%,1!"
if not "%o%" equ "" (call :b64-h1by1) else (goto :hex-hex2)
set/a i+=1
goto :base64-hex
:hex-hex2
if not defined hex goto :hex2-str
for /l %%a in (1,1,4) do (
set/a "n=2*(%%a-1)"
call set x=%%hex:~!n!,2%%
set "ec%%a=0x!x!"
if "!x!" equ "40" (set ec%%a=0& set f%%a=0)
)
set hex=%hex:~8%
set/a c1=%ec1%"<<"2"|"%ec2%">>"4
set/a c2=%ec2%"<<"4"|"%ec3%">>"2
set/a c3=%ec3%"<<"6"|"%ec4%
for /l %%a in (1,1,3) do (
set/a c%%a=!c%%a!"&"255
call :dec-hex !c%%a!
)
if "%f3%" equ "0" set "c2="
if "%f4%" equ "0" set "c3="
for /l %%a in (1,1,3) do call set "hex2=%%hex2%%%%r!c%%a!%%"
goto :hex-hex2
:hex2-str
set vbs=%tmp%\tt.vbs
if exist %vbs% goto :runVBS
:createVBS
set t=^>^>%vbs% echo
%t%h=wscript.arguments(0)
%t%s=""
%t%for i=1 to len(h) step 2
%t% a=cint("&h"^&mid(h,i,2))
%t% if a^>160 then
%t% a=cint("&h"^&mid(h,i,4))
%t% i=i+2
%t% end if
%t% s=s^&chr(a)
%t%next
%t%wscript.stdout.write(s)
:runVBS
for /f %%a in ('cscript//nologo %vbs% %hex2%') do set "s=%%a"
:print
echo.
echo.%s%
pause
goto :eof
:b64-h1by1
for /l %%a in (0,1,64) do (
if "!base64:~%%a,1!" equ "%o%" (
call :dec-hex %%a
set hex=!hex!!r%%a!
goto :eof
)
)
goto :eof
:dec-hex
set "r%1="
set "h=0123456789ABCDEF"
set/a q=%1
:1c
set/a r=%q%%%16
set/a q=%q%/16
call set r=%%h:~%r%,1%%
set r%1=%r%!r%1!
if not %q% equ 0 goto :1c
if %1 leq 0xf set r%1=0!r%1!
主要修改一下这两处:
1、for /f %%a in ('cscript//nologo %vbs% %hex2%') do set "s=%%a"
2、echo.%s%
@echo off
::::::::Base64 Decode {s11ss 2007-12-3}::::::::
setlocal enabledelayedexpansion
:GetEs
echo 请输入要转换的base64编码:
set/p es=
if "%es%"=="" goto GetEs
echo 转换中...
set "base64=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
set/a i=0
:base64-hex
set "o=!es:~%i%,1!"
if not "%o%" equ "" (call :b64-h1by1) else (goto :hex-hex2)
set/a i+=1
goto :base64-hex
:hex-hex2
if not defined hex goto :hex2-str
for /l %%a in (1,1,4) do (
set/a "n=2*(%%a-1)"
call set x=%%hex:~!n!,2%%
set "ec%%a=0x!x!"
if "!x!" equ "40" (set ec%%a=0& set f%%a=0)
)
set hex=%hex:~8%
set/a c1=%ec1%"<<"2"|"%ec2%">>"4
set/a c2=%ec2%"<<"4"|"%ec3%">>"2
set/a c3=%ec3%"<<"6"|"%ec4%
for /l %%a in (1,1,3) do (
set/a c%%a=!c%%a!"&"255
call :dec-hex !c%%a!
)
if "%f3%" equ "0" set "c2="
if "%f4%" equ "0" set "c3="
for /l %%a in (1,1,3) do call set "hex2=%%hex2%%%%r!c%%a!%%"
goto :hex-hex2
:hex2-str
set vbs=%tmp%\tt.vbs
if exist %vbs% goto :runVBS
:createVBS
set t=^>^>%vbs% echo
%t%h=wscript.arguments(0)
%t%s=""
%t%for i=1 to len(h) step 2
%t% a=cint("&h"^&mid(h,i,2))
%t% if a^>160 then
%t% a=cint("&h"^&mid(h,i,4))
%t% i=i+2
%t% end if
%t% s=s^&chr(a)
%t%next
%t%wscript.stdout.write(s)
:runVBS
for /f "delims=" %%a in ('cscript//nologo %vbs% %hex2%') do set "s=%%a"
:print
echo.
echo 转换结果(不包括最外边的一对引号):
echo."%s%"
pause
goto :eof
:b64-h1by1
for /l %%a in (0,1,64) do (
if "!base64:~%%a,1!" equ "%o%" (
call :dec-hex %%a
set hex=!hex!!r%%a!
goto :eof
)
)
goto :eof
:dec-hex
set "r%1="
set "h=0123456789ABCDEF"
set/a q=%1
:1c
set/a r=%q%%%16
set/a q=%q%/16
call set r=%%h:~%r%,1%%
set r%1=%r%!r%1!
if not %q% equ 0 goto :1c
if %1 leq 0xf set r%1=0!r%1! [ Last edited by s11ss on 2008-8-29 at 08:50 PM ]
此帖被 +20 点积分 点击查看详情 评分人:【 zh159 】 | 分数: +20 | 时间:2007-12-3 17:26 |
|
|
|
2007-12-3 17:22 |
|
|
knoppix7
银牌会员
积分 1287
发帖 634
注册 2007-5-2 来自 cmd.exe
状态 离线
|
『第
2 楼』:
话说VBS不能把VBS变量写到CMD里?
VBS做这种事情还是方便啊..
|
|
2007-12-3 17:24 |
|
|
zh159
金牌会员
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第
3 楼』:
批处理版通讯录很有用^_^
|
|
|
2007-12-3 17:27 |
|
|
knoppix7
银牌会员
积分 1287
发帖 634
注册 2007-5-2 来自 cmd.exe
状态 离线
|
|
2007-12-3 17:29 |
|
|
vkill
金牌会员
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第
5 楼』:
我近来初以为是 debug ,vbs 还是很好的
|
|
2007-12-3 20:59 |
|
|
s11ss
银牌会员
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『第
6 楼』:
Quote: | Originally posted by vkill at 2007-12-3 08:59 PM:
我近来初以为是 debug ,vbs 还是很好的 |
|
vkill兄要不用debug来试试?我认为这个完全绝对百分之百不能用debug实现,呵呵
|
|
2007-12-3 22:09 |
|
|
vkill
金牌会员
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2007-12-4 19:51 |
|
|
gamevyo
初级用户
积分 32
发帖 13
注册 2007-12-27
状态 离线
|
『第
8 楼』:
楼主有没有测试过这个代码?
在执行到
:runVBS
for /f %%a in ('cscript//nologo %vbs% %hex2%') do set "s=%%a"
这里会出现 %a 的值为“输入错误”的情况
我对VBS一窍不通,谁能来帮忙看下是怎么回事?
|
邮件地址去掉123 |
|
2008-8-28 17:37 |
|
|
gamevyo
初级用户
积分 32
发帖 13
注册 2007-12-27
状态 离线
|
『第
9 楼』:
求解,不要沉啊
|
邮件地址去掉123 |
|
2008-8-29 09:06 |
|
|
s11ss
银牌会员
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『第
10 楼』:
Quote: | Originally posted by gamevyo at 2008-8-28 05:37 PM:
在执行到
:runVBS
for /f %%a in ('cscript//nologo %vbs% %hex2%') do set "s=%%a"
这里会出现 %a 的值为“输入错误”的情况
我对VBS一窍不通,谁能来帮忙看下是怎么回事? |
|
代码当然是测试过才发的啊~~~~~~~~~
你测试的base64编码是什么?
|
|
2008-8-29 13:32 |
|
|
gamevyo
初级用户
积分 32
发帖 13
注册 2007-12-27
状态 离线
|
『第
11 楼』:
奇怪了,刚试了下,又没问题了,不过解出来好像不对
我测试的是这段:
QUFmdHA6Ly9mcmVlMV93d3cuMTdoYXBweS5jbl8xMDM1NjY0Mjc3OjA5Q0NGMTFCM0NDNzZCQzIzRkM2NjI0Q0NCNTZEOEFBJjEyMjAwMDUzNzBAY2Z0cDEuMTdoYXBweS5jbjoyMi+2r7utv+IvPT09wazU2NbQtcS2r7utv+I9PT0vSCC67C9bd3d3LjE3aGFwcHkuY25dW2t1cmVuYV1bMDldLnJtdmJaWg==
解出来的是:
UVVGbWRIQTZMeTltY21WbE1WOTNkM2N1TVRkb1lYQndlUzVqYmw4eE1ETTFOalkwTWpjM09qQTVRME5HTVRGQ00wTkROelpDUXpJelJrTTJOakkwUTBOQ05UWkVPRUZCSmpFeU1qQXdNRFV6TnpCQVkyWjBjREV1TVRkb1lYQndlUzVqYmpveU1pKzJyN3V0ditJdlBUMDl3YXpVMk5iUXRjUzJyN3V0ditJOVBUMHZTQ0M2N0M5YmQzZDNMakUzYUdGd2NIa3VZMjVkVzJ0MWNtVnVZVjFiTURsZExuSnRkbUphV2c9PQ==
貌似不对啊。。
|
邮件地址去掉123 |
|
2008-8-29 19:28 |
|
|
s11ss
银牌会员
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『第
12 楼』:
Quote: | Originally posted by gamevyo at 2008-8-29 07:28 PM:
奇怪了,刚试了下,又没问题了,不过解出来好像不对
我测试的是这段:
QUFmdHA6Ly9mcmVlMV93d3cuMTdoYXBweS5jbl8xMDM1NjY0Mjc3OjA5Q0NGMTFCM0NDNzZCQzIzRkM2NjI0Q0NCNTZEOEFBJ ... |
|
解密出来确实不对,但是也不是你的这个结果啊?太离奇了~~
|
|
2008-8-29 20:44 |
|
|
261001126
初级用户
积分 25
发帖 13
注册 2007-1-18
状态 离线
|
|
2008-12-2 19:24 |
|