from tkinter import Tk,simpledialog,messagebox
def is_even(number):
return number %2==0
def get_even_letters(message):
even_letters=[]
for counter in range(0,len(message)):
if is_even(counter):
even_letters.append(message[counter])
return even_letters
def get_odd_letters(message):
odd_letters=[]
for counter in range(0,len(message)):
if not is_even(counter):
odd_letters.append(counter)
return odd_letters
def swap_letters(message):
letter_list=[]
if not is_even(len(message)):
message=message+'x'
even_letters=get_even_letters(message)
odd_letters=get_odd_letters(message)
for counter in range(0,int(len(message)/2)):
letter_list.append(odd_letters[counter])
letter_list.append(even_letters[counter])
new_message=''.join(map(str,letter_list))
return new_message
def get_task():
task=simpledialog.askstring('任务','你想加密还是解密?')
return task
def get_message():
message=simpledialog.askstring('消息','输入机密消息(提示:请输入英文):')
return message
root=Tk()
root.withdraw()
while True:
task=get_task()
if task=='加密':
message=get_message()
encrypted=swap_letters(message)
messagebox.showinfo('机密消息的密文是:',encrypted)
elif task=='解密':
message = get_message()
decrypted=swap_letters(message)
messagebox.showinfo('机密消息的明文是:',decrypted)
else:
break
root.mainloop()
链接: https://pan.baidu.com/s/10ND2OnDD7i9Z7qKK7_Yyvw 提取码:qji3