和我的上一篇文章中的代码逻辑相同,无非就是将key从0-25遍历一遍,直接放代码
from tkinter import *
def hydry(event):
message=str(b1.get()).upper()
letter='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
sult = ''
for key in range(26):
for i in message:
if i in letter:
num = letter.find(i)
num = num - key
if num >= len(letter):
num = num - len(letter)
if num < 0:
num = num + len(letter)
sult = sult + letter[num]
else:
sult = sult + i
sult=sult+'\n'
lib.config(text=str(sult))
root=Tk()
root.title('暴力破解凯撒密码')
root.geometry('1080x720')
b1=Entry(root,text='输入待破解的密文')
b1.place(relx=0.1,rely=0.1,relwidth=0.5,relheight=0.1)
b2=Button(root,text='开始破解')
b2.place(relx=0.1,rely=0.2,relwidth=0.1,relheight=0.1)
b2.bind('<1>',hydry)
lib=Label(root,text='结果')
lib.place(relx=0.1,rely=0.3, relwidth=0.6, relheight=0.7)
root.mainloop()
运行结果: