所以基本上我在写一个工具,对字母旋转密码的所有可能答案进行暴力破解,然后将它们全部打印到屏幕上。我如何防止特殊字符和空格旋转,让它们保持原样
#!/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()
在最里面的循环中,检查字符是否不在字母表中,如果不在字母表中,则跳过循环的其余部分
相关问题 更多 >
编程相关推荐