因此,基本上,我正在编写一种工具,将所有可能的答案强加给字母表旋转密码,然后将它们全部打印到屏幕上。如何防止特殊字符和空格旋转,并保持原样。
#!/usr/bin/env python3
# alphabeth and key variables
import sys
alpha_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alpha_lower = "abcdefghijklmnopqrstuvwxyz"
cipher_text = sys.argv[1]
def crack_rotation():
for key in range(len(alpha_lower)):
plain_text = ''
for character in cipher_text:
if character == character.lower():
index = alpha_lower.find(character)
index = (index-key)%len(alpha_lower)
plain_text += alpha_lower[index]
else:
index = alpha_upper.find(character)
index = (index-key)%len(alpha_upper)
plain_text += alpha_upper[index]
print('Trying with key %s. Result = %s' %(key, plain_text))
crack_rotation()
答案 0 :(得分:1)
在最里面的循环中检查字符是否不在字母表中,如果不是,请跳过循环的其余部分。
if character not in alpha_upper + alpha_lower:
plaintext += character
continue