我创建了一个批处理文件,用于使用6位数关键字对邮件进行编码。但我注意到它切换字母有问题,我似乎无法解决它。有谁知道该怎么办?这是我的代码:
@echo off
Setlocal enabledelayedexpansion
Title Cipher
Set abc=abcdefghijklmnopqrstuvwxyz
Set L1=%abc:~0,1%
Set L2=%abc:~1,1%
Set L3=%abc:~2,1%
Set L4=%abc:~3,1%
Set L5=%abc:~4,1%
Set L6=%abc:~5,1%
Set L7=%abc:~6,1%
Set L8=%abc:~7,1%
Set L9=%abc:~8,1%
Set L10=%abc:~9,1%
Set L11=%abc:~10,1%
Set L12=%abc:~11,1%
Set L13=%abc:~12,1%
Set L14=%abc:~13,1%
Set L15=%abc:~14,1%
Set L16=%abc:~15,1%
Set L17=%abc:~16,1%
Set L18=%abc:~17,1%
Set L19=%abc:~18,1%
Set L20=%abc:~19,1%
Set L21=%abc:~20,1%
Set L22=%abc:~21,1%
Set L23=%abc:~22,1%
Set L24=%abc:~23,1%
Set L25=%abc:~24,1%
Set L26=%abc:~25,1%
:: will need showdrive.bat's determination of letters
:Enter
Cls
Echo Enter a 6 letter Word
Echo for your keyword.
Echo.
Set /p keyword="Keyword>"
If %keyword%==%keyword% goto Alphabet
:Alphabet
Set k1=%keyword:~0,1%
Set k2=%keyword:~1,1%
Set k3=%keyword:~2,1%
Set k4=%keyword:~3,1%
Set k5=%keyword:~4,1%
Set k6=%keyword:~5,1%
Set string=%abc%
:: Erases letters from alphabet
call set "string=%%string:!k1!=%%"
call set "string=%%string:!k2!=%%"
call set "string=%%string:!k3!=%%"
call set "string=%%string:!k4!=%%"
call set "string=%%string:!k5!=%%"
call set "string=%%string:!k6!=%%"
Echo %k1% %k2% %k3% %k4% %k5% %k6%
Echo %abc%
Set "newabc=%keyword%%string%"
Echo %newabc%
pause
Echo.
Echo Enter text to encode
set /p te="Text>"
if "%te%"=="%te%" goto ghp
:ghp
:: then need to divide up all 26 characters using showdrive
:: Eg. NA=k
:: L1=a Replace L1 with NA
set N1=%newabc:~0,1%
set N2=%newabc:~1,1%
set N3=%newabc:~2,1%
set N4=%newabc:~3,1%
set N5=%newabc:~4,1%
set N6=%newabc:~5,1%
set N7=%newabc:~6,1%
set N8=%newabc:~7,1%
set N9=%newabc:~8,1%
set N10=%newabc:~9,1%
set N11=%newabc:~10,1%
set N12=%newabc:~11,1%
set N13=%newabc:~12,1%
set N14=%newabc:~13,1%
set N15=%newabc:~14,1%
set N16=%newabc:~15,1%
set N17=%newabc:~16,1%
set N18=%newabc:~17,1%
set N19=%newabc:~18,1%
set N20=%newabc:~19,1%
set N21=%newabc:~20,1%
set N22=%newabc:~21,1%
set N23=%newabc:~22,1%
set N24=%newabc:~23,1%
set N25=%newabc:~24,1%
set N26=%newabc:~25,1%
:: Done New letters
set t2=%te%
set t2=%t2: =_%
call set "t2=%%t2:a=!N1!%%"
call set "t2=%%t2:b=!N2!%%"
call set "t2=%%t2:c=!N3!%%"
call set "t2=%%t2:d=!N4!%%"
call set "t2=%%t2:e=!N5!%%"
call set "t2=%%t2:f=!N6!%%"
call set "t2=%%t2:g=!N7!%%"
call set "t2=%%t2:h=!N8!%%"
call set "t2=%%t2:i=!N9!%%"
call set "t2=%%t2:j=!N10!%%"
call set "t2=%%t2:k=!N11!%%"
call set "t2=%%t2:l=!N12!%%"
call set "t2=%%t2:m=!N13!%%"
call set "t2=%%t2:n=!N14!%%"
call set "t2=%%t2:o=!N15!%%"
call set "t2=%%t2:p=!N16!%%"
call set "t2=%%t2:q=!N17!%%"
call set "t2=%%t2:r=!N18!%%"
call set "t2=%%t2:s=!N19!%%"
call set "t2=%%t2:t=!N20!%%"
call set "t2=%%t2:u=!N21!%%"
call set "t2=%%t2:v=!N22!%%"
call set "t2=%%t2:w=!N23!%%"
call set "t2=%%t2:x=!N24!%%"
call set "t2=%%t2:y=!N25!%%"
call set "t2=%%t2:z=!N26!%%"
Echo.
Echo %t2%
pause
答案 0 :(得分:1)
你的问题 - 至少是你的主要问题 - 是逻辑之一,而不是编程。
当您替换旧信的新信时,如果您替换说" g"会发生什么?为" a"?
apple - > gpple
然后你用其他东西代替" g" ...
还要考虑重复字母作为关键字一部分的效果。查看var onlyOneVariableIsFalse = ((a ? 0 : 1) + (b ? 0 : 1) ... (f ? 0 : 1)) == 1;
的显示,以获取newabc