我想解析密文相对简单,而且效率也应该比加密要高,方法我也用的很常规:- @echo off&setlocal enabledelayedexpansion
- set "str1=17-5-5-1 8-2-2-4 17-10-4-4 9-8-3-1 3-2-5-3 21-7-1-2 15-9-1-3"
- set "str2=24-5-3-1 10-5-3-4 28-5-1-2 3-2-5-3 21-7-1-2 7-10-4-4 25-5-4-4 32-1-5-3 31-3-5-3 25-7-1-2 12-2-4-1 3-2-5-1"
- for /l %%i in (1,1,2) do (
- for %%j in (!str%%i!) do (
- for /f "delims=- tokens=1-4" %%k in ("%%j") do (
- call :search %%k %%l %%m %%n
- )
- set str=!str!!word!
- )
- echo 密文:!str%%i!
- echo 原文:!str!&set str=
- )
- echo.&pause>nul
-
- :search
- set/a line=(%1-1)*13+%2+2
- set/a cols=%3+1
- set tmp=0
- for /f "delims=" %%i in (homebook.txt) do (
- set/a tmp+=1
- if !tmp!==!line! (
- for /f "tokens=%cols%" %%j in ("%%i") do (
- for /f "delims=- tokens=%4" %%k in ("%%j") do set word=%%k
- goto eof
- )
- )
- )
-
- :eof
复制代码 而加密感觉相对麻烦点,而且里面的几个“函数”效率都较低,尤其是算列数用了echo|find 这种方法,效率大减。但是搞了一中午累得很,头有点大,不想再改了,看其他兄弟的了:- @echo off&setlocal enabledelayedexpansion
- set "str1=我想他肯定知道这个地方有段好难走的路"
- set "str2=当敌人冲过来后你就拉响前面的警报"
- for /l %%i in (1,1,2) do (
- for /f "delims=" %%j in ("!str%%i!") do (
- set str=%%j&call :split
- )
- echo 原文:!str%%i!
- echo 密文:!code!&set code=
- )
- echo.&pause>nul
-
- :split
- call :search !str:~0,1!
- set code=!code! !singlecode!
- set str=!str:~1!
- if "!str!"=="" goto eof
- goto split
-
-
- :search
- ::为了避开汉字表中的"第,行,版"三个字,搜索时采用-*或*-的格式
- findstr "\-%1" homebook.txt >nul&& call :transform \-%1
- findstr "%1\-" homebook.txt >nul&& call :transform %1\-
- goto eof
-
- :transform
- for /f "delims=: tokens=1-3" %%i in ('findstr/n "%1" homebook.txt') do (
- set tmpstr=%1&set tmpstr=!tmpstr:\-=!
- set 实际行数=%%i
- set tmp=%%j&set tmp=!tmp:第=!&set 版块行数=!tmp:行=!
- set count=
- for %%l in (%%k) do (
- set/a count+=1
- echo %%l|find "!tmpstr!">nul&&set 版块列数=!count!&&call :计算列中序数 !
-
- tmpstr! %%l
- )
- )
- if !实际行数! lss 15 set 版块数=1
- if !实际行数! geq 15 set/a 版块数=(!实际行数!-!版块行数!+12)/14
- set singlecode=!版块数!-!版块行数!-!版块列数!-!列中序数!
- goto eof
-
-
- :计算列中序数
- set tmpstr=%2&set tmpstr=!tmpstr:-= !
- set count=
- for %%i in (!tmpstr!) do (
- set/a count+=1
- if %%i==%1 set 列中序数=!count!
- )
-
- :eof
复制代码
[ 本帖最后由 wankoilz 于 2009-11-26 15:45 编辑 ] |