-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.py
More file actions
63 lines (45 loc) · 1.31 KB
/
Example.py
File metadata and controls
63 lines (45 loc) · 1.31 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
import tkinter.filedialog as fd
from tkinter import *
key = 100
# ---------------- 1. Functions start
def Encrypt():
file = open(filename, "rb")
data = file.read()
file.close()
data = bytearray(data)
for index, value in enumerate(data):
data[index] = value ^ key
file = open(filename, "wb")
file.write(data)
file.close()
def Decrypt():
file = open(filename, "rb")
data = file.read()
file.close()
data = bytearray(data)
for index, value in enumerate(data):
data[index] = value ^ key
file = open(filename, "wb")
file.write(data)
file.close()
def select():
global filename
filename = fd.askopenfilename()
label1.config(text=filename)
# --------------- 1. function ends
# -------------2. Tkinter code start
root = Tk()
root.geometry('300x300')
root.title("Cryptography")
label = Label(root, text="Select file to encrypt or decrypt")
selectfile = Button(root, text="Select a file", command=select)
label1 = Label(root, text="No file selected")
button_enc = Button(root, text="Encrypt/Decrypt", command=Encrypt)
label2 = Label(root, text="-")
label.pack()
label1.pack()
label2.pack()
selectfile.pack()
button_enc.pack()
root.mainloop()
# ------------------------Tkinter code ends