『第
2 楼』:
程序需要 sed.exe ,我用sed 是为了加快速度 ,希望达人优化下,用纯P写个出来
@echo off&setlocal ENABLEDELAYEDEXPANSION
title p-文本文件加密解密器 V:1.0 by:vkill
::<config>
set "回车=↑"
set "补=↓"
set "连接="
set "t_=test.tx"
set "tools=sed.exe"
::max正n框这里不要修改,数字小了加密相对不安全,大了程序会出错
set "max正n框=10"
::默认密码和操作
set "pass=1,,,;1,3,2,;12,4,5,3"
set "加解=-"
::特殊字符的替换
:: ! 被临时替换为 ←
:: : 被临时替换为 →
::<start>
md "%t_%" >nul 2>nul
pushd "%t_%"
del /f/q *.* >nul 2>nul
for %%? in (/?;-?;-h;--h) do (if "%~1"=="%%?" goto help_)
call :test_
set/p=^当前不可处理的字符有%回车%、%补%、←、→<nul
echo.
echo.
:加解选择
if not "%~3"=="" (set "加解=%~3") else (set/p=^加密/解密[+/-]^<!加解!^>:<nul&set/p "加解= ")
if not "%加解%"=="+" (if not "%加解%"=="-" goto 加解选择)
:文件选择
if not "%~1"=="" (set "life=%~1") else (set/p=^请把你要!加解!密的文件拖放到本窗口:<nul&set/p "life= ")
if not exist "%life%" (echo 你要!加解!的文件不存在,请重新选择&goto 文件选择)
:输入密码
if "%加解%"=="-" (
for /f "tokens=2 delims=%连接%" %%? in ('findstr "^%连接%解密密码%连接%" "%life%"') do (set "pass=%%?")
)
if not "%~2"=="" (set "pass=%~1") else (set/p=^请输入密码^<!pass!^>:<nul&set/p "pass= ")
copy "%life%" llife>nul 2>nul
echo.
echo 正在重新排列文件,请稍侯......
echo.
if "%加解%"=="+" (call :加密)
if "%加解%"=="-" (call :解密)
::<end>
popd
echo.
echo 重新排列完成,程序2秒后退出
ping -n 3 0x7F000001>nul
goto :eof
::<all call>::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:加密
::<获层and定义字符变量-+>
::%life%行尾加%回车%,并替换特殊字符!和:
sed "s/$/%回车%/" llife|more>la%t_%
setlocal DISABLEDELAYEDEXPANSION
sed "s/!/←/g;s/:/→/g" la%t_%|more>a%t_%
setlocal ENABLEDELAYEDEXPANSION
::每个字符单独一行,去掉回车多出的空行
sed "s/[\x81-\xFE][\x40-\xFE]/&\n/g;s/[\x20-\x7F]/&\n/g" a%t_%|sed "/^$/d"|more>b%t_%
::计算总共多少字符
for /f %%? in ('sed -n "$=" b%t_%') do (set maxn=%%?)
::判断看用多大的框子
for /l %%? in (1,1,%max正n框%) do (
set/a y=%%?%%2
set/a s=%%?/2
if "!y!"=="1" (
set/a "层=!s!+1"
set/a zn=!zn!+%%?*4
if %maxn% lss !zn! goto 判断框子ok
)
)
:判断框子ok
::补够数
if %maxn% lss %zn% (set/a 需补=%zn%-%maxn%) else (set/a 需补=%zn%-%maxn%%%%zn%)
for /l %%? in (1,1,!需补!) do (>>b%t_% echo %补%)
sed -e "/^$/d" -e "$a\%补%" b%t_%|more>c%t_%
::定义每个字符为对应变量数字
for /f "tokens=1,2 delims=:" %%a in ('findstr /N . c%t_%') do (set "%%a=%%b"&set "maxshu=%%a")
call :share
set/a "文件个数=%maxshu%/%zn%"
::<写完整变量文件--加密>
cd.>e%t_%
set n=0
for /l %%? in (1,1,%文件个数%) do (
for /f "tokens=1-2 delims=%连接%" %%a in (d%t_%) do (
set/a v=%%a+%zn%*!n!
>>e%t_% echo !v!
)
set/a n+=1
)
::<写文件-+>
cd.>f%t_%
>>f%t_% echo %连接%原文件名%连接%%life%
>>f%t_% echo %连接%解密密码%连接%%pass%
>>f%t_% echo %连接%请到http://blog.yx127.com/?action=show^&id=222下载[ p-文本文件加密解密器.cmd ]程序解密
>>f%t_% echo.
cd.>g%t_%
set n=0
for /f "tokens=*" %%a in (e%t_%) do (
>>g%t_% set/p=^%连接%^!%%a!<nul
set/a n+=1
set/a ls=!n!%%!正n!
if "!ls!"=="0" (set/a "hs+=1" &>>g%t_% echo.)
if "!hs!"=="!正n!" (set "hs=0")
)
::再把特殊字符替换回来
sed "s/%连接%//g" g%t_%|more>lh%t_%
setlocal DISABLEDELAYEDEXPANSION
sed "s/←/!/g;s/→/:/g" lh%t_%|more>h%t_%
setlocal ENABLEDELAYEDEXPANSION
copy/b f%t_%+h%t_% ..\"(加密后)life.txt">nul 2>nul
goto :eof
:解密
::<获层and-->
copy llife xllife>nul 2>nul
setlocal DISABLEDELAYEDEXPANSION
sed "s/!/←/g" xllife|more>llife
setlocal ENABLEDELAYEDEXPANSION
set hz=0
for /f "eol=%连接% tokens=*" %%? in ('findstr . llife') do (set "line=%%?%回车%" & set/a hz+=1)
call :解密获正n "%line%"
set/a 层=%正n%/2
call :share
set/a zn=%正n%*%正n%
set/a 文件个数=%hz%/%正n%
::<写完整变量文件--解密>
cd.>e%t_%
set n=0
for /l %%? in (1,1,%文件个数%) do (
for /f "tokens=1-2 delims=%连接%" %%a in (d%t_%) do (
for /f "tokens=1 delims=hl" %%z in ('echo %%b') do (set/a h_=%%z+%正n%*!n!)
for /f "tokens=2 delims=l" %%z in ('echo %%b') do (set l_=%%z)
set/a v=%%a+%zn%*!n!
>>e%t_% echo !v!%连接%h!h_!l!l_!
)
set/a n+=1
)
::从小到大重新1-n变量
set/a shuz=%hz%*%正n%
cd.>f%t_%
for /l %%? in (1,1,%shuz%) do (>>f%t_% findstr "^%%?%连接%" e%t_%)
for /f "tokens=1-2 delims=%连接%" %%a in (f%t_%) do (set %%b=)
::定义字符变量
set n=0
for /f "eol=%连接% tokens=*" %%? in ('findstr . llife') do (set/a n+=1& set "line=%%?" & call :解密定义字符变量 "!n!")
::<写文件-->
cd.>g%t_%
for /f "tokens=1-2 delims=%连接%" %%a in (f%t_%) do (
if ^!%%b!==^%回车% (>>g%t_% echo.) else (>>g%t_% set/p=^%补%^!%%b!<nul)
)
::去%补%
sed "s/%补%//g" g%t_% |more>h%t_%
setlocal DISABLEDELAYEDEXPANSION
sed "s/←/!/g" h%t_%|more>"..\(解密后)life.txt"
setlocal ENABLEDELAYEDEXPANSION
:写文件--end
goto :eof
:share
::<share>::::::::::::::::::::::::::::::::::::::::
::拆密码
set ns=0
set ne=4
for /l %%? in (1,1,!层!) do (
call :set层pass %%? !ns! !ne!
set/a ns=!ns!+!ne!+1,ne=!ne!+2
)
::补全空密码
for /l %%? in (1,1,!层!) do (
if "!层%%?pass!"=="" (
set/a 个数=2*%%?-1
set/a 上=%%?-1
set/a 上个数=2*!上!-1
set/a x个数=!上个数!+1
::这里补密码是后面补的形式,可以任意
set 补p=
for /l %%a in (!x个数!,1,!个数!) do (set 补p=!补p!%%a)
call :补pass %%? !上! !补p!
)
)
::细化密码
for /l %%? in (1,1,!层!) do (
set/a 个数=2*%%?-1
for /f "tokens=1-4 delims=," %%a in ('echo !层%%?pass!') do (
call :xm %%? !个数! 1 %%a
call :xm %%? !个数! 2 %%b
call :xm %%? !个数! 3 %%c
call :xm %%? !个数! 4 %%d
)
)
::用四文件组一个四方型
::直接写一文件
call :echo_life 1 !层!
copy 1.txt x1.txt>nul 2>nul
::写二文件后右转
call :echo_life 2 !层!
call :2右转 !层! 2 x2
::写三文件后倒置后取反
call :echo_life 3 !层!
call :3倒置 !层! 3 x3
::写四文件后左转
call :echo_life 4 !层!
call :4左转 !层! 4 x4
sed "1i\%补%" x4.txt|more>left.txt
sed "$a\%补%" x2.txt|more>right.txt
sed $rx3.txt x1.txt|more>center.txt
set/a 正n=2*!层!
cd.>框.txt
for /l %%? in (1,1,!正n!) do (
for %%a in (left;center;right) do (
for /f "tokens=*" %%b in ('sed -n "%%?p" %%a.txt') do (>>框.txt set/p=^%%b<nul)
)
>>框.txt echo.
)
sed "s/%补%//g" 框.txt|more>x框.txt
::计算每转一次写几个字
set/a mn=(!正n!*!正n!)/4
:::::::::::::::::::::这里我是从左到右,从上到下写的,转是右旋转,这里看你爱好自由:::::::::::::::::::::::::::
::给每个实加变量
set "d_shu=0"
copy x框.txt x1框.txt>nul 2>nul
call :加变量 x1框
call :2右转 !正n! x1框 x2框
call :加变量 x2框
call :2右转 !正n! x2框 x3框
call :加变量 x3框
call :2右转 !正n! x3框 x4框
call :加变量 x4框
::写出对应变量到文件
cd.>d%t_%
for /l %%a in (1,1,!正n!) do (
for /l %%b in (1,1,!正n!) do (>>d%t_% echo !h%%al%%b!%连接%h%%al%%b)
)
goto :eof
::<share end>::::::::::::::::::::::::::::::::::::
:set层pass
set "层%1pass=!pass:~%2,%3!"
goto :eof
:xm
for /l %%? in (1,1,%2) do set s%%?=
set %1→%3=
set var=%4
if not "!var!"=="" (
for /l %%? in (0,1,%2) do (
set "v=!var:~%%?,1!"
if not "!v!"=="" (set "s!v!=ok")
)
)
for /l %%? in (1,1,%2) do (
if defined s%%? (set "%1→%3→%%?=实") else (set "%1→%3→%%?=空")
)
goto :eof
:echo_life
cd.>%1.txt
for /l %%? in (%2,-1,1) do (
set/a 个数=2*%%?-1
set/a v=%2-%%?
set var=
if not !v!==0 (for /l %%i in (1,1,!v!) do (set var=!var!%补%))
>>%1.txt set/p=^!var!<nul
for /l %%~ in (1,1,!个数!) do (>>%1.txt set/p=^!%%?→%1→%%~!<nul)
>>%1.txt set/p=^!var!<nul
>>%1.txt echo.
)
goto :eof
:2右转
cd.>%3.txt
set/a 个数=2*%1-1
set n=0
:loop_2右转
for /l %%? in (%1,-1,1) do (
for /f "tokens=*" %%a in ('sed -n %%?p "%2.txt"') do (
set v=%%a
>>%3.txt set/p=^!v:~%n%,1!<nul
)
)
>>%3.txt echo.
set/a n+=1
if !n!==!个数! goto :eof
goto loop_2右转
goto :eof
:3倒置
cd.>%3.txt
cd.>l%3.txt
for /l %%? in (%1,-1,1) do (sed -n %%?p "%2.txt"|more>>l%3.txt)
for /f "tokens=*" %%a in (l%3.txt) do (
call :取反 %%a
>>%3.txt echo !ret!
)
goto :eof
:4左转
cd.>%3.txt
set/a 个数=2*%1-1
set n=!个数!
:loop_4左转
set/a n-=1
for /l %%? in (1,1,%1) do (
for /f "tokens=*" %%a in ('sed -n %%?p "%2.txt"') do (
set v=%%a
>>%3.txt set/p=^!v:~%n%,1!<nul
)
)
>>%3.txt echo.
if !n!==0 goto :eof
goto loop_4左转
goto :eof
:取反
set "str=%~1"
set "var=!str:~0,1!!var!"
set "ret=!var!"
set "flag=!str:~1!"
if defined flag call :取反 "!flag!"
set str= && set var=
goto :eof
:加变量
for /l %%a in (1,1,!正n!) do (
for /f "tokens=*" %%? in ('sed -n "%%ap" %1.txt') do (call :啄字比较 %%a %%? !正n!)
)
goto :eof
:啄字比较
set n=0
set var=%2
:loop_啄字比较
set v=!var:~%n%,1!
set/a n+=1
if "!v!"=="实" (set/a "d_shu+=1" & set h%1l%n%=!d_shu!)
if %n%==%3 goto :eof
goto loop_啄字比较
goto :eof
:补pass
set "层%1pass=!层%2pass!%3"
goto :eof
:解密获正n
set "v=%~1"
for /l %%i in (100,-1,0) do (
set "vl=!v:~%%i,1!"
if ^!vl!==^%回车% (set "正n=%%i"&goto :eof)
)
goto :eof
:解密定义字符变量
set "h=%~1"
set/a lin=%正n%-1
for /l %%i in (0,1,%lin%) do (
set/a l=%%i+1
set "h!h!l!l!=!line:~%%i,1!"
)
goto :eof
:help_
echo 任意键退出
pause>nul
goto :eof
:test_
for %%? in (%tools%) do (
if *%%~$PATH:?==* if not exist %%? (
set/p=程序所需文件%%?.exe缺少,已开始自动下载...<nul
if not exist iget.vbs (call :iget.vbs_)
iget.vbs "http://www.yx127.com/tools/%%?" "..\%%?"
set/p=下载ok<nul
)
echo.
)
cls
goto :eof
:iget.vbs_
>iget.vbs echo x=LCase(WScript.Arguments(1))
>>iget.vbs echo y=LCase(WScript.Arguments(0))
>>iget.vbs echo Set xPost=CreateObject("Microsoft.XMLHTTP")
>>iget.vbs echo xPost.Open "GET",y,0
>>iget.vbs echo xPost.Send()
>>iget.vbs echo Set sGet=CreateObject("ADODB.Stream")
>>iget.vbs echo sGet.Mode=3
>>iget.vbs echo sGet.Type=1
>>iget.vbs echo sGet.Open()
>>iget.vbs echo sGet.Write(xPost.responseBody)
>>iget.vbs echo sGet.SaveToFile x,2
goto :eof [ Last edited by vkill on 2007-4-8 at 07:37 AM ]
附件
1: 文本文件加密(测试版本.rar (2007-3-25 05:57, 2.22 K,下载次数: 189)
附件
2: p-文本文件加密解密器 V1.0(bate).rar (2007-4-8 03:03, 3.43 K,下载次数: 193)
附件
3: p-文本文件加密解密器.cmd V-1.0.rar (2007-4-8 07:36, 3.79 K,下载次数: 281)
|