标题: [原创]********Escape加密和Unescape解密********
[打印本页]
作者: s11ss
时间: 2007-11-3 14:44
标题: [原创]********Escape加密和Unescape解密********
@echo off
::::::::Escape And Unescape {s11ss 2007-11-3}::::::::
::Instruction:
::1.For the limitation of the CMD,some codes such as "&" and other special codes can not be encrypted correctly.
::2.When you try to use the encrypted form to visit a website,please do not encrypt the words "http://".For instance,you would like to visit "http://www.cn-dos.net".You should do like this:
::%0 www.cn-dos.net
::Then you will get "%77%77%77%2E%63%6E%2D%64%6F%73%2E%6E%65%74",through which you can visit it.
::Receive arguments:
if "%1" equ "" (
echo Two Arguments:
echo 1. /e ^(escape^) or /u ^(unescape^)
echo 2. a string
echo e.g.:
echo %0 /e www.cn-dos.net
echo %0 /u %%77%%77%%77%%2E%%63%%6E%%2D%%64%%6F%%73%%2E%%6E%%65%%74
echo.
:Rec
echo You can input arguments here too,like /e www.cn-dos.net:
call :GetArg
) else (set str1=%1&set str2=%2)
set str=%str2%
if "%str%" equ "" goto :Rec
if "%str1%" equ "/u" goto :Unescape
::Judge if run for the first time:
<"%~f0" more +130|find "::Data">nul&&goto :Escape||echo Run for the first time,please wait...
::Create a temporary file in which there is an ASCII value table:
>>%0 echo.
>>%0 echo.
>>%0 echo ::Data
set s= !"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
set/a n=0
:CreateFile
call set char="%%s:~%n%,1%%"
set/a n+=1,ascii=%n%+32
call :10to16 %ascii%
>>%0 echo %r% %char%
if not %n% equ 95 goto :CreateFile
::Encrypt codes one by one:
:Escape
echo Encrypting...
set/a num=0
call set o=%%str:~%num%,1%%
::The next two same statements define which code needs not to be encrypted:
::1.call :exception /
setlocal enabledelayedexpansion
:ec1
for /f "usebackq skip=131 delims=" %%a in (%0) do (
set "v=%%a"
if "%o%" equ "!v:~-2,1!" (
set ns=!ns!%%!v:~0,2!
goto :ec2
)
)
call :eChinese %o%
set/p x=<t
set ns=!ns!%x%
:ec2
set/a num+=1
call set o=%%str:~%num%,1%%
::2.call :exception /
if not "%o%" equ "" goto :ec1
::Output the result:
echo.
echo Complete:
echo !ns!
goto :End
::Decrypt by javascript:
:Unescape
echo Decrypting...
mshta "javascript:t=unescape('%str%');f=new ActiveXObject('Scripting.FileSystemObject');f=f.CreateTextFile('t');f.Write(t);close()"
set/p str=<t
echo.
echo Complete:
echo %str%
:End
del t 2>nul
echo.
echo Press Any Key To Exit...
pause>nul
goto :eof
::Functions
:GetArg
set/p str=
for /f "tokens=1* delims= " %%a in ("%str%") do (set str1=%%a& set str2=%%b)
goto :eof
:10to16
set/a q=%1
:1c
set/a r=%q%%%16
set/a q=%q%/16
call set r=%%r:10=A%%
call set r=%%r:11=B%%
call set r=%%r:12=C%%
call set r=%%r:13=D%%
call set r=%%r:14=E%%
call set r=%%r:15=F%%
call set r%1=%r%%%r%1%%
if not %q% equ 0 goto :1c
call set r=%%r%1%%
set r%1=
goto :eof
:exception
if "%o%" equ "%1" (
set ns=%ns%%1
goto :ec2
)
goto :eof
:eChinese
mshta "javascript:t=escape('%1');f=new ActiveXObject('Scripting.FileSystemObject');f=f.CreateTextFile('t');f.Write(t);close()"
goto :eof
[
Last edited by s11ss on 2007-11-4 at 12:04 AM ]
作者: knoppix7
时间: 2007-11-5 09:28
好东西。学习中.
作者: vkill
时间: 2007-11-6 19:24
我觉得 <"%~f0" more +130 这样写不好,要是别人删除上某写空行或自己加点注释就不能用了,建议使用 call goto
作者: bjsh
时间: 2007-11-7 02:48
Quote: |
Originally posted by vkill at 2007-11-6 07:24 PM:
我觉得 <"%~f0" more +130 这样写不好,要是别人删除上某写空行或自己加点注释就不能用了,建议使用 call goto |
|
看过lz发的几个帖子;
有很多地方用到了这个东西;
确实容易出现问题; vkill 说的很有道理
作者: s11ss
时间: 2007-12-5 17:39
能得到bjsh和vkii两位大虾l的指点,鄙人受宠若惊啊。
但不能否认这句的好处——可以把某些脚本代码原封不动的附在批处理文件尾部,使批处理代码更具可读性。
作者: vkill
时间: 2007-12-6 20:09
Quote: |
Originally posted by s11ss at 2007-12-5 17:39:
能得到bjsh和vkii两位大虾l的指点,鄙人受宠若惊啊。
但不能否认这句的好处——可以把某些脚本代码原封不动的附在批处理文件尾部,使批处理代码更具可读性。 |
|
最后你说的这个可以这样实现
@echo off&endlocal&setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=1 delims=:" %%? in ('findstr /N "=Hiddenpass.cmd_s=" "%oneself%"') do (more +%%? %oneself%>"%temp%\a")
for /f "tokens=1 delims=:" %%? in ('findstr /N "=Hiddenpass.cmd_e=" "%oneself%"') do (set/a "a=%%?-1" & more +!a! %oneself%>"%temp%\b")
findstr /V /B /E /G:"%temp%\b" "%temp%\a">"%temp%\pass.cmd"
exit
=Hiddenpass.cmd_s=
@echo off
chcp 437>nul&graftabl 936>nul
echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5x>in.com
echo (注:输入密码时不明文显示)
set /p password=请输入mail:%~1的密码:<nul
for /f "tokens=*" %%i in ('in.com') do set password=%%i
del in.com
echo.
>%temp%\pass set password
exit
=Hiddenpass.cmd_e=
作者: knoppix7
时间: 2007-12-6 20:29
其实也没有说必须把所有的代码封装到一个BAT里.
所以。分开也可以把 。