-
Notifications
You must be signed in to change notification settings - Fork 344
/
enc.py
84 lines (64 loc) · 2.07 KB
/
enc.py
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
77
78
79
80
81
82
83
84
from tkinter import *
import pybase64
from tkinter import messagebox
root = Tk()
root.title('Codemy.com - Encrypt/Decrpt Base64')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("500x400")
def clear():
#Clear boxes
my_text.delete(1.0, END)
my_entry.delete(0, END)
def encrypt():
# Get text from text box
secret = my_text.get(1.0, END)
# Clear the text box
my_text.delete(1.0, END)
# Logic for password
if my_entry.get() == "elder":
# Convert to byte
secret = secret.encode("ascii")
# Convert to base64
secret = pybase64.b64encode(secret)
# Convert it back to ascii
secret = secret.decode("ascii")
# Print to text box
my_text.insert(END, secret)
else:
# Flash a message if wrong password
messagebox.showwarning("Incorrect!", "Incorrect Password, Try Again!")
def decrypt():
# Get text from text box
secret = my_text.get(1.0, END)
# Clear the screen
my_text.delete(1.0, END)
# Logic for password
if my_entry.get() == "elder":
# Convert to byte
secret = secret.encode("ascii")
# Convert to base64
secret = pybase64.b64decode(secret)
# Convert it back to ascii
secret = secret.decode("ascii")
# Print to text box
my_text.insert(END, secret)
else:
# Flash a message if wrong password
messagebox.showwarning("Incorrect!", "Incorrect Password, Try Again!")
my_frame = Frame(root)
my_frame.pack(pady=20)
enc_button = Button(my_frame, text="Encrypt", font=("Helvetica", 18), command=encrypt)
enc_button.grid(row=0, column=0)
dec_button = Button(my_frame, text="Decrypt", font=("Helvetica", 18), command=decrypt)
dec_button.grid(row=0, column=1, padx=20)
clear_button = Button(my_frame, text="Clear", font=("Helvetica", 18), command=clear)
clear_button.grid(row=0, column=2)
enc_label = Label(root, text="Encrypt/Decrypt Text...", font=("Helvetica", 14))
enc_label.pack()
my_text = Text(root, width=57, height=10)
my_text.pack(pady=10)
password_label = Label(root, text="Enter Your Password...", font=("Helvetica", 14))
password_label.pack()
my_entry = Entry(root, font=("Helvetica", 18), width=35, show="*")
my_entry.pack(pady=10)
root.mainloop()