|
| 1 | +from tkinter import* |
| 2 | +import random |
| 3 | +import time |
| 4 | +import datetime |
| 5 | + |
| 6 | +root=Tk() |
| 7 | +root.geometry("1600x8000") |
| 8 | +root.title("Message Encryption and Decryption") |
| 9 | + |
| 10 | +Tops=Frame(root, width=1600,relief=SUNKEN) |
| 11 | +Tops.pack(side=TOP) |
| 12 | + |
| 13 | +f1=Frame(root,width=800,height=700,relief=SUNKEN) |
| 14 | +f1.pack(side=LEFT) |
| 15 | + |
| 16 | +#================================================================================= |
| 17 | +# TIME |
| 18 | +#================================================================================ |
| 19 | +localtime=time.asctime(time.localtime(time.time())) |
| 20 | + |
| 21 | +lblInfo=Label(Tops,font=('helvetica',50,'bold'),text="SECRET MESSAGING \n Vigen�re cipher",fg="Black",bd=10,anchor='w') |
| 22 | +lblInfo.grid(row=0,column=0) |
| 23 | + |
| 24 | +lblInfo=Label(Tops,font=('arial',20,'bold'),text=localtime,fg="Steel Blue",bd=10,anchor='w') |
| 25 | +lblInfo.grid(row=1,column=0) |
| 26 | + |
| 27 | +rand = StringVar() |
| 28 | +Msg=StringVar() |
| 29 | +key=StringVar() |
| 30 | +mode=StringVar() |
| 31 | +Result=StringVar() |
| 32 | + |
| 33 | +def qExit(): |
| 34 | + root.destroy() |
| 35 | + |
| 36 | +def Reset(): |
| 37 | + rand.set("") |
| 38 | + Msg.set("") |
| 39 | + key.set("") |
| 40 | + mode.set("") |
| 41 | + Result.set("") |
| 42 | + |
| 43 | + |
| 44 | +#reference |
| 45 | +lblReference= Label(f1, font=('arial', 16, 'bold'),text="Name:",bd=16,anchor="w") |
| 46 | +lblReference.grid(row=0, column=0) |
| 47 | +txtReference=Entry(f1, font=('arial',16,'bold'),textvariable=rand,bd=10,insertwidth=4,bg="powder blue",justify='right') |
| 48 | +txtReference.grid(row=0,column=1) |
| 49 | + |
| 50 | +lblMsg= Label(f1, font=('arial', 16, 'bold'),text="MESSAGE",bd=16,anchor="w") |
| 51 | +lblMsg.grid(row=1, column=0) |
| 52 | +txtMsg=Entry(f1, font=('arial',16,'bold'),textvariable=Msg,bd=10,insertwidth=4,bg="powder blue",justify='right') |
| 53 | +txtMsg.grid(row=1,column=1) |
| 54 | + |
| 55 | +lblkey= Label(f1, font=('arial', 16, 'bold'),text="KEY",bd=16,anchor="w") |
| 56 | +lblkey.grid(row=2, column=0) |
| 57 | +txtkey=Entry(f1, font=('arial',16,'bold'),textvariable=key,bd=10,insertwidth=4,bg="powder blue",justify='right') |
| 58 | +txtkey.grid(row=2,column=1) |
| 59 | + |
| 60 | +lblmode= Label(f1, font=('arial', 16, 'bold'),text="MODE(e for encrypt,d for decrypt)",bd=16,anchor="w") |
| 61 | +lblmode.grid(row=3, column=0) |
| 62 | +txtmode=Entry(f1, font=('arial',16,'bold'),textvariable=mode,bd=10,insertwidth=4,bg="powder blue",justify='right') |
| 63 | +txtmode.grid(row=3,column=1) |
| 64 | + |
| 65 | +lblService= Label(f1, font=('arial', 16, 'bold'),text="The Result-",bd=16,anchor="w") |
| 66 | +lblService.grid(row=2, column=2) |
| 67 | +txtService=Entry(f1, font=('arial',16,'bold'),textvariable=Result,bd=10,insertwidth=4,bg="powder blue",justify='right') |
| 68 | +txtService.grid(row=2,column=3) |
| 69 | + |
| 70 | +import base64 |
| 71 | +def encode(key, clear): |
| 72 | + enc = [] |
| 73 | + for i in range(len(clear)): |
| 74 | + key_c = key[i % len(key)] |
| 75 | + enc_c = chr((ord(clear[i]) + ord(key_c)) % 256) |
| 76 | + enc.append(enc_c) |
| 77 | + return base64.urlsafe_b64encode("".join(enc).encode()).decode() |
| 78 | + |
| 79 | +def decode(key, enc): |
| 80 | + dec = [] |
| 81 | + enc = base64.urlsafe_b64decode(enc).decode() |
| 82 | + for i in range(len(enc)): |
| 83 | + key_c = key[i % len(key)] |
| 84 | + dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256) |
| 85 | + dec.append(dec_c) |
| 86 | + return "".join(dec) |
| 87 | + |
| 88 | +def Ref(): |
| 89 | + print("Message= " ,(Msg.get())) |
| 90 | + |
| 91 | + clear=Msg.get() |
| 92 | + k=key.get() |
| 93 | + m=mode.get() |
| 94 | + |
| 95 | + if(m=='e'): |
| 96 | + Result.set(encode(k,clear)) |
| 97 | + else: |
| 98 | + Result.set(decode(k,clear)) |
| 99 | + |
| 100 | + |
| 101 | +btnTotal=Button(f1,padx=16,pady=8,bd=16,fg="black",font=('arial',16,'bold'),width=10,text="Show Message",bg="powder blue",command=Ref).grid(row=7,column=1) |
| 102 | + |
| 103 | +btnReset=Button(f1,padx=16,pady=8,bd=16,fg="black",font=('arial',16,'bold'),width=10,text="Reset",bg="green",command=Reset).grid(row=7,column=2) |
| 104 | + |
| 105 | +btnExit=Button(f1,padx=16,pady=8,bd=16,fg="black",font=('arial',16,'bold'),width=10,text="Exit",bg="red",command=qExit).grid(row=7,column=3) |
| 106 | + |
| 107 | +root.mainloop() |
0 commit comments