[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
我想解析密文相对简单,而且效率也应该比加密要高,方法我也用的很常规:
  1. @echo off&setlocal enabledelayedexpansion
  2. 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"
  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"
  4. for /l %%i in (1,1,2) do (
  5.    for %%j in (!str%%i!) do (
  6.       for /f "delims=- tokens=1-4" %%k in ("%%j") do (
  7.       call :search %%k %%l %%m %%n
  8.       )
  9.       set str=!str!!word!
  10.    )
  11. echo 密文:!str%%i!
  12. echo 原文:!str!&set str=
  13. )
  14. echo.&pause>nul
  15. :search
  16. set/a line=(%1-1)*13+%2+2
  17. set/a cols=%3+1
  18. set tmp=0
  19. for /f "delims=" %%i in (homebook.txt) do (
  20.    set/a tmp+=1
  21.    if !tmp!==!line! (
  22.       for /f "tokens=%cols%" %%j in ("%%i") do (
  23.          for /f "delims=- tokens=%4" %%k in ("%%j") do set word=%%k
  24.          goto eof
  25.       )
  26.    )
  27. )
  28. :eof
复制代码
而加密感觉相对麻烦点,而且里面的几个“函数”效率都较低,尤其是算列数用了echo|find 这种方法,效率大减。但是搞了一中午累得很,头有点大,不想再改了,看其他兄弟的了:
  1. @echo off&setlocal enabledelayedexpansion
  2. set "str1=我想他肯定知道这个地方有段好难走的路"
  3. set "str2=当敌人冲过来后你就拉响前面的警报"
  4. for /l %%i in (1,1,2) do (
  5.    for /f "delims=" %%j in ("!str%%i!") do (
  6.    set str=%%j&call :split
  7.    )
  8. echo 原文:!str%%i!
  9. echo 密文:!code!&set code=
  10. )
  11. echo.&pause>nul
  12. :split
  13. call :search !str:~0,1!
  14. set code=!code! !singlecode!
  15. set str=!str:~1!
  16. if "!str!"=="" goto eof
  17. goto split
  18. :search
  19. ::为了避开汉字表中的"第,行,版"三个字,搜索时采用-*或*-的格式
  20. findstr "\-%1" homebook.txt >nul&& call :transform \-%1
  21. findstr "%1\-" homebook.txt >nul&& call :transform %1\-
  22. goto eof
  23. :transform
  24. for /f "delims=: tokens=1-3" %%i in ('findstr/n "%1" homebook.txt') do (
  25.    set tmpstr=%1&set tmpstr=!tmpstr:\-=!
  26.    set 实际行数=%%i
  27.    set tmp=%%j&set tmp=!tmp:第=!&set 版块行数=!tmp:行=!
  28.    set count=
  29.    for %%l in (%%k) do (
  30.    set/a count+=1
  31.    echo %%l|find "!tmpstr!">nul&&set 版块列数=!count!&&call :计算列中序数 !
  32. tmpstr! %%l
  33.    )
  34. )
  35. if !实际行数! lss 15 set 版块数=1
  36. if !实际行数! geq 15 set/a 版块数=(!实际行数!-!版块行数!+12)/14
  37. set singlecode=!版块数!-!版块行数!-!版块列数!-!列中序数!
  38. goto eof
  39. :计算列中序数
  40. set tmpstr=%2&set tmpstr=!tmpstr:-= !
  41. set count=
  42. for %%i in (!tmpstr!) do (
  43. set/a count+=1
  44. if %%i==%1 set 列中序数=!count!
  45. )
  46. :eof
复制代码

[ 本帖最后由 wankoilz 于 2009-11-26 15:45 编辑 ]
2

评分人数

    • pusofalse: 学习了。PB + 5
    • batman: 不错,但效率真的很不尽人意PB + 15

TOP

回复 9楼 的帖子

我也是看只有4个字,只循环4次,所以也就直接for了,是不大周密....

TOP

superman ......O(∩_∩)O哈哈~.......

TOP

看过《风声》了,开始是兴奋,中途是愤怒,最后是无限的感动,真的被感动了... ...
于是我也努力写了摩尔斯密码的vbs版,纪念下这部经典国产影片,和女主角--晓梦... ..
由于把母本整合进了脚本,所以直接发附件。
1

评分人数

    • batman: 为爱国情怀叫好加分!PB + 20

TOP

返回列表