Menu

Please Fix Rotation Cipher Encrypts Decrypts Displays Message Box Tkinter Import Tkinter I Q43866788

Can you please fix the rotation cipher below, so that itencrypts and decrypts. and displays in the message box.

from tkinter import *from tkinter import messageboxfrom tkinter import ttkroot = Tk()root.geometry(‘500×500’) # declares the size of the formroot.title(“Two Integer Rotation Cipher”)# variable to store all the alphabetsletters = ‘abcdefghijklmnopqrstuvwxyz’def encrypt(text, shift): # variable to store the encrypted text enc = ” # for every word in encrypted text for word in text.split(): # for every character in the word for c in word: # if character is in letters if c in letters: # finding the index of ‘c’ in letters i = letters.find(c) # adding the number of shifts from the index i = i + 2 + int(shift) # adds 2 to initial rotation = 3 if i > 25: i = i – len(letters) # finding the corresponding characters for the index in letters and stored in enc(encryption) enc += letters[i] else: enc += c enc += ‘ ‘ #textAns.delete(1.0, ‘end’) textAns.insert(0, END)def decrypt(text, shift): # variable to store the decrypted text dec = ” # for every word in decrypted text for word in text.split(): # for every character in the word for a in word: # changes the rotation integer # if character is in letters if a in letters: # finding the index of ‘c’ in letters i = letters.find(a) # subtracting the number of shifts from the index i = i – int(shift) if i < 0: i = i + len(letters) # finding the corresponding characters for the index in letters and stored in dec(decryption) dec += letters[i] else: dec += a dec += ‘ ‘ textAns.delete(1.0, ‘end’) textAns.insert(0, dec)def Convert(): if c.get() == “Select Choice”: tkMessageBox.showinfo(“Error”, “Please select the Choice”) else: try: r = int(entry_2.get()) if c.get() == “Encrypt a message”: encrypt(entry_1.get(), r) elif c.get() == “Decrypt a message”: encrypt(entry_1.get(), r) except ValueError: # Handle the exception tkMessageBox.showinfo(“Error”, “Invalid input. Rotation step should be an integer”)label_1 = Label(root, text=”Enter Text”, width=20, font=(“bold”, 10))label_1.place(x=10, y=30)entry_1 = Entry(root, width=50)# adding the entryentry_1.place(x=150, y=30)label_2 = Label(root, text=”Select Choice”, width=20, font=(“bold”, 10))label_2.place(x=10, y=70)# adding the drop down listlist1 = [‘Encrypt a message’, ‘Decrypt a message’]c = StringVar()droplist = OptionMenu(root, c, *list1)droplist.config(width=15)c.set(‘Select Choice’)droplist.place(x=150, y=70)label_3 = Label(root, text=”Size of Rotation”, width=20, font=(“bold”, 10))label_3.place(x=10, y=120)entry_2 = Entry(root, width=10)# adding the entryentry_2.place(x=150, y=120)Button(root, text=’Click’, width=20, bg=’brown’, fg=’white’, command=Convert).place(x=180, y=180)label_3 = Label(root, text=”Answer: “, width=20, font=(“bold”, 10))label_3.place(x=10, y=220)textAns = Text(root, height=10, width=37)textAns.place(x=150, y=220)root.mainloop()

Expert Answer


Answer to Can you please fix the rotation cipher below, so that it encrypts and decrypts. and displays in the message box. from tk…

OR