用替换法效率更高,缺点需要一个中介字符,本代码中用的是#号,也就是文本内不能含#号。
:- @echo off&setlocal enabledelayedexpansion
- ::创建随机字典
- set "code= abcdefghijklmnopqrstuvwxyz"
- set "code2=a b c d e f g h i j k l m n o p q r s t u v w x y z"
- set /a dd=27
- set wjm=a.txt
- for /l %%a in (13 -1 1) do (
- set /a dd-=1,ww=!random!%%dd+1
- for %%i in (!ww!) do set "aa=!code:~%%i,1!"
- for %%i in (!aa!) do set "code=!code:%%i=!"
- set /a dd-=1,ww=!random!%%dd+1
- for %%i in (!ww!) do set "bb=!code:~%%i,1!"
- for %%i in (!bb!) do set "code=!code:%%i=!"
- set .!aa!=!bb!&set ".!bb!=!aa!"
- )
- set num=a&echo.密文>c.txt
- :loop 加密、解密为同一代码。
- for /f "%skip% delims=" %%a in (%wjm%) do (
- if not defined num echo 原文>>c.txt
- set num=%%a&setlocal
- for %%i in (!code2!) do (
- if not defined ..%%i (
- set num=!num:%%i=#!
- for %%j in (!.%%i!) do set num=!num:%%j=%%i!&set num=!num:#=%%j!
- set ..%%i=a&set ..!.%%i!=a
- )
- )
- >>c.txt echo.!num!
- endlocal
- )
- set "num="&echo.>>c.txt
- if "!wjm!"=="a.txt" set wjm=c.txt&set "skip=skip=1"&goto loop
- start c.txt
复制代码
|