Skip to content

Commit 3eb55c2

Browse files
authored
Add files via upload
0 parents  commit 3eb55c2

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

mod.py

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
from tkinter import *
2+
import random
3+
import time
4+
import datetime
5+
import easygui
6+
7+
root = Tk()
8+
9+
root.geometry("1200x1600")
10+
root.title("Encyption and Decryption")
11+
Tops = Frame(root, width = 1600, relief = "flat")
12+
Tops.pack(side = TOP)
13+
f1 = Frame(root, width = 800,height = 700, relief = "flat")
14+
f1.pack(side = LEFT)
15+
16+
localtime = time.asctime(time.localtime(time.time()))
17+
18+
lblInfo = Label(Tops,font=("Helevitica",50,"bold"),text="Secret Messaging", fg="black",bd = 10,anchor="w")
19+
lblInfo.grid(row=0, column=0)
20+
21+
lblInfo = Label(Tops,font = ("Arial",20,"bold"), text = localtime, fg = "steelblue", bd=10, anchor = "w")
22+
lblInfo.grid(row=1,column=0)
23+
24+
rand = StringVar()
25+
Msg = StringVar()
26+
key = StringVar()
27+
mode = StringVar()
28+
Result = StringVar()
29+
30+
def qExit():
31+
root.destroy()
32+
def Reset():
33+
rand.set("")
34+
Msg.set("")
35+
key.set("")
36+
mode.set("")
37+
Result.set("")
38+
lblReference = Label(f1, font=("Arial" , 16,"bold"),text="Name",bd=10,anchor="w")
39+
lblReference.grid(row=0,column=0)
40+
txtReference =Entry(f1, font=("Arial",16,"bold"),textvariable=rand,bd=1,bg="white",justify="left")
41+
txtReference.grid(row=0,column=1)
42+
lblMsg = Label(f1, font=('arial', 16, 'bold'),
43+
text="MESSAGE", bd=1, anchor="w")
44+
45+
lblMsg.grid(row=1, column=0)
46+
47+
txtMsg = Entry(f1, font=('arial', 16, 'bold'),
48+
textvariable=Msg, bd=1, insertwidth=4,
49+
bg="white", justify='left')
50+
51+
txtMsg.grid(row=1, column=1)
52+
53+
lblkey = Label(f1, font=('arial', 16, 'bold'),
54+
text="KEY", bd=1, anchor="w")
55+
56+
lblkey.grid(row=2, column=0)
57+
58+
txtkey = Entry(f1, font=('arial', 16, 'bold'),
59+
textvariable=key, bd=1, insertwidth=4,
60+
bg="white", justify='left')
61+
62+
txtkey.grid(row=2, column=1)
63+
64+
lblmode = Label(f1, font=('arial', 16, 'bold'),
65+
text="MODE(e for encrypt, d for decrypt)",
66+
bd=1, anchor="w")
67+
68+
lblmode.grid(row=3, column=0)
69+
70+
txtmode = Entry(f1, font=('arial', 16, 'bold'),
71+
textvariable=mode, bd=1, insertwidth=4,
72+
bg="white", justify='left')
73+
74+
txtmode.grid(row=3, column=1)
75+
76+
lblService = Label(f1, font=('arial', 16, 'bold'),
77+
text="The Result-", bd=1, anchor="w")
78+
79+
lblService.grid(row=2, column=2)
80+
81+
txtService = Entry(f1, font=('arial', 16, 'bold'),
82+
textvariable=Result, bd=1, insertwidth=4,
83+
bg="white", justify='left')
84+
85+
txtService.grid(row=2, column=3)
86+
87+
import base64
88+
89+
90+
# Function to encode
91+
def encode(key, clear):
92+
enc = []
93+
94+
for i in range(len(clear)):
95+
key_c = key[i % len(key)]
96+
enc_c = chr((ord(clear[i]) +
97+
ord(key_c)) % 256)
98+
99+
enc.append(enc_c)
100+
101+
return base64.urlsafe_b64encode("".join(enc).encode()).decode()
102+
103+
def decode(key, enc):
104+
dec = []
105+
106+
enc = base64.urlsafe_b64decode(enc).decode()
107+
for i in range(len(enc)):
108+
key_c = key[i % len(key)]
109+
dec_c = chr((256 + ord(enc[i]) -
110+
ord(key_c)) % 256)
111+
112+
dec.append(dec_c)
113+
return "".join(dec)
114+
def Wrong():
115+
easygui.msgbox("Wrong Choice","Alert")
116+
def Ref():
117+
print("Message= ", (Msg.get()))
118+
119+
clear = Msg.get()
120+
k = key.get()
121+
m = mode.get()
122+
123+
if (m == 'e'):
124+
Result.set(encode(k, clear))
125+
elif (m=='d'):
126+
Result.set(decode(k, clear))
127+
else:
128+
print(Wrong())
129+
# Show message button
130+
131+
132+
btnTotal = Button(f1, padx=16, pady=8, bd=16, fg="black",
133+
font=('arial', 16, 'bold'), width=10,
134+
text="Show Message", bg="white",
135+
command=Ref).grid(row=7, column=1)
136+
137+
# Reset button
138+
btnReset = Button(f1, padx=16, pady=8, bd=16,
139+
fg="black", font=('arial', 16, 'bold'),
140+
width=10, text="Reset", bg="green",
141+
command=Reset).grid(row=7, column=2)
142+
143+
# Exit button
144+
btnExit = Button(f1, padx=16, pady=8, bd=16,
145+
fg="black", font=('arial', 16, 'bold'),
146+
width=10, text="Exit", bg="red",
147+
command=qExit).grid(row=7, column=3)
148+
149+
# keeps window alive
150+
root.mainloop()

0 commit comments

Comments
 (0)