另一种思路,不生成方阵,只计算索引数,加解密支持空格.
密匙:key with space
文本:this is a simple test this is a simple test this is a simple test
模式(1.加密[默认] 2.解密):1
结果:DMGSWRLHASHJPUWJYTAAMHT YTCNCEZ ORFXLXPUHXDERHEATQSSQAVNXUJEWBY T
请按任意键继续. . .
密匙:key with space
文本:DMGSWRLHASHJPUWJYTAAMHT YTCNCEZ ORFXLXPUHXDERHEATQSSQAVNXUJEWBY T
模式(1.加密[默认] 2.解密):2
结果:THIS IS A SIMPLE TEST THIS IS A SIMPLE TEST THIS IS A SIMPLE TEST
请按任意键继续. . .
- cls&@echo off&SETLOCAL ENABLEDELAYEDEXPANSION
- set "str=. ABCDEFGHIJKLMNOPQRSTUVWXYZ" & set sMAX=27
- :main
- set/p keystring=密匙:
- set/p string=文本:
- set/p mode=模式(1.加密[默认] 2.解密):
- set/p=结果:<nul
- set mode=%mode%1
- set mode=%mode:~0,1%
- call :getkeyword
- set/a i=0,l=1
- :loop
- call :index !string:~%i%,1!
- if %mode% equ 2 (
- set/a idx=index+sMAX-offset%l%
- ) else (
- set/a idx=index+offset%l%
- )
- if %idx% gtr %sMAX% set/a idx%%=sMAX
- set/p=!str:~%idx%,1!<nul
- set/a i+=1,l= l %% keylength + 1
- if not "!string:~%i%,1!"=="" goto:loop
- echo.&pause&goto:main
- :getkeyword
- set i=0
- :lp
- if "!keystring:~%i%,1!"=="" goto:eof
- call :index !keystring:~%i%,1!
- set/a i+=1
- set/a offset!i!=%index%-1,keylength=i
- goto:lp
- :index
- set index=1
- if "%1"=="" goto:eof
- for %%a in (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) do if %1 geq %%a set/a index+=1
复制代码
[ 本帖最后由 dishuo 于 2008-8-23 15:35 编辑 ] |