我正在尝试编写自己的 python 代码来暴力破解凯撒密码,我需要一些帮助。我在函数代码的末尾特别需要帮助。我想知道如何专门打印,以便在每个键尝试后都有一个间隙。我正在使用 python 3.3,并且在 3 周前才开始编码。
print ("The plaintext will be stripped of any formatting such as spaces.")
freqlist = []
maxkey = 26
if key > maxkey:
raise Exception("Enter a key between 0 and 26: ")
elif key < 0:
raise Exception("Enter a key between 0 and 26: ")
freq = []
inpt=input("Please enter the cipher text:")
inpt = inpt.upper()
inpt = inpt.replace(" ", "")
inpt = inpt.replace(",", "")
inpt = inpt.replace(".", "")
for i in range(0,27):
key = i
def decrypt():
for i in range(0,27):
for a in inpt:
b=ord(a)
b-= i
if b > ord("Z"):
b -= 26
elif b < ord("A"):
b+=26
freqlist.append(b)
for a in freqlist:
d=chr(a)
freq.append(d)
freq="".join(freq)
print(freq.lower(),"\n")
decrypt()
我正在尝试使用 for 循环,但我认为它并不能真正有效地工作。