-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsproject.py
More file actions
76 lines (75 loc) · 2.96 KB
/
Isproject.py
File metadata and controls
76 lines (75 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from tkinter import *
import base64
from tkinter import messagebox
import tkinter.font as font
def encode(key, msg):
enc = []
for i in range(len(msg)):
list_key = key[i % len(key)]
list_enc = chr((ord(msg[i]) +
ord(list_key)) % 256)
enc.append(list_enc)
return base64.urlsafe_b64encode("".join(enc).encode()).decode()
def decode(key, code):
dec = []
enc = base64.urlsafe_b64decode(code).decode()
for i in range(len(enc)):
list_key = key[i % len(key)]
list_dec = chr((256 + ord(enc[i]) - ord(list_key)) % 256)
dec.append(list_dec)
return "".join(dec)
wn = Tk()
wn.geometry("500x500")
wn.configure(bg='white')
wn.title("Encrypt and Decrypt your Messages")
Message = StringVar()
key = StringVar()
mode = IntVar()
Output = StringVar()
headingFrame1 = Frame(wn,bg="gray91",bd=5)
headingFrame1.place(relx=0.2,rely=0.1,relwidth=0.7,relheight=0.16)
headingLabel = Label(headingFrame1,bg='white', text=" Welcome to Encryption and \nDecryption", fg='grey19', font=('Courier',15,'bold'))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
label1 = Label(wn, text='Enter the Message',bg='white', font=('Courier',10))
label1.place(x=10,y=150)
msg = Entry(wn,textvariable=Message, width=35, font=('calibre',10,'normal'))
msg.place(x=200,y=150)
label2 = Label(wn, text='Enter the key',bg='white', font=('Courier',10))
label2.place(x=10,y=200)
InpKey = Entry(wn, textvariable=key, width=35,font=('calibre',10,'normal'))
InpKey.place(x=200,y=200)
label3 = Label(wn, text='Check one of encrypt or decrypt',bg='white', font=('Courier',10))
label3.place(x=10,y=250)
Radiobutton(wn, text='Encrypt',bg='white', variable=mode, value=1).place(x=100,y=300)
Radiobutton(wn, text='Decrypt',bg='white', variable=mode, value=2).place(x=200,y=300)
label3 = Label(wn, text='Result',bg='white', font=('Courier',10))
label3.place(x=10,y=350)
res = Entry(wn,textvariable=Output, width=35, font=('calibre',10,'normal'))
res.place(x=200,y=350)
#Function that executes on clicking Show Message function in python message encryption decryption project
def Result():
msg = Message.get()
k= key.get()
i = mode.get()
if (i==1):
Output.set(encode(k, msg))
elif(i==2):
Output.set(decode(k, msg))
else:
messagebox.showinfo('ProjectGurukul', 'Please Choose one of Encryption or Decryption. Try again.')
#Function that executes on clicking Reset function
def Reset():
Message.set("")
key.set("")
mode.set(0)
Output.set("")
ShowBtn = Button(wn,text="Show Message",bg='green', fg='black',width=15,height=1,command=Result)
ShowBtn['font'] = font.Font( size=12)
ShowBtn.place(x=180,y=400)
ResetBtn = Button(wn, text='Reset', bg='blue', fg='black', width=15,height=1,command=Reset)
ResetBtn['font'] = font.Font( size=12)
ResetBtn.place(x=15,y=400)
QuitBtn = Button(wn, text='Exit', bg='red', fg='black',width=15,height=1, command=wn.destroy)
QuitBtn['font'] = font.Font( size=12)
QuitBtn.place(x=345,y=400)
wn.mainloop()