I have a python code snippet that coverts the Mac address to another code using caesar ciphertext: The code is given below:
import uuid
def getmac():
mac_num = hex(uuid.getnode()).replace('0x', '').upper()
mac = ''.join(mac_num[i : i + 2] for i in range(0, 11, 2))
return mac
plaintext = getmac()
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
key = 1
cipher = ''
for c in plaintext:
if c in alphabet:
cipher += alphabet[(alphabet.index(c) + key +3)%(len(alphabet))]
print('Code:' + cipher)
This works proper as it prints out the code to the Python shell, however when i Edit the same code with TKinter library, I get concatenation and other errors , The code used in TKinter lib is given below: In this snippet the function of the program is same ,however i just want the mac address to be input from the user and when he clicks on submit ,the code is prompted to him:
import uuid
from Tkinter import *
root = Tk()
root.title("Code Generator")
root.geometry("250x200+200+100")
root.resizable(width=False, height=False)
cipher = ''
Label(root, text='Mac Address:').grid(row=0, sticky=W, padx=4)
Entry(root).grid(row=0, column=1, sticky=E, pady=4)
Label(root, text="Code:").grid(row=1, sticky=W, padx=4)
hlbl = Label(root, text=cipher, width=20)
hlbl.grid(row=0, column=2, sticky=E, pady=4)
def get_it():
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
for c in text:
if c in alphabet:
cipher += alphabet[(alphabet.index(c) + key + 2) % (len(alphabet))]
Button(root, text="Submit", command=get_it).grid(row=2, column=1)
root.mainloop()
when i run the program i get this:
When i enter a random text and click submit i get this:
What changes should i make?