-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNDA_accessibility.py
220 lines (159 loc) · 7.38 KB
/
NDA_accessibility.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
from fileinput import filename
from operator import truediv
import tkinter as tk
from tkinter import ttk
import tkinter.font as font
from tkinter import filedialog as fd
from tkinter.messagebox import showinfo
import os
import sys
from urllib.parse import quote
import webbrowser
def select_file_en():
global en_filename
filetypes = (
('All files', '*.*'),
)
filename = fd.askopenfilename(
title='Choose a file to encrypt',
initialdir='/',
filetypes=filetypes)
showinfo(
title='Selected File',
message=filename
)
en_filename = filename
def select_file_de():
global de_filename
filetypes = (
('All files', '*.*'),
)
filename = fd.askopenfilename(
title='Choose a file to decrypt',
initialdir='/',
filetypes=filetypes)
showinfo(
title='Selected File',
message=filename
)
de_filename = filename
def select_key():
global de_key
filetypes = (
('All files', '*.*'),
)
key = fd.askopenfilename(
title='Choose a file to decrypt',
initialdir='/',
filetypes=filetypes)
showinfo(
title='Selected File',
message=key
)
de_key = key
def encrypt(en_filename):
to_encrypt = open(en_filename, "rb").read()
size = len(to_encrypt)
key = os.urandom(size)
with open(en_filename + ".key", "wb") as key_out:
key_out.write(key)
encrypted = bytes(a^b for (a,b) in zip(to_encrypt, key))
with open(en_filename, "wb") as encrypted_out:
encrypted_out.write(encrypted)
showinfo(
title='Encryption successful',
message=(en_filename + " is now encrypted")
)
def decrypt(de_filename, de_key):
file = open(de_filename, "rb").read()
key = open(de_key, "rb").read()
decrypted = bytes(a^b for (a,b) in zip(file, key))
with open(de_filename, "wb") as decrypted_out:
decrypted_out.write(decrypted)
"""
if():
showinfo(
title='Decryption successful',
message=(de_filename + " is now decrypted")
)
else:
showinfo(
title='Error',
message=("Decryption failed, make sure to pick the right files.")
)
"""
root = tk.Tk()
root.configure(bg='#EEAABB')
root.title('NDA Accessibility Alpha v.03')
window_width = 600
window_height = 400
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
center_x = int(screen_width/2 - window_width / 2)
center_y = int(screen_height/2 - window_height / 2)
root.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}')
root.resizable(False, False)
root.attributes('-alpha',1)
root.attributes('-topmost', 0)
program_directory=sys.path[0]
root.iconphoto(True, tk.PhotoImage(file=os.path.join(program_directory, "favicon.png")))
def openHelpWindow():
help = tk.Tk()
help.configure(bg='#EEAABB')
help.title('Help')
window_width = 400
window_height = 300
screen_width = help.winfo_screenwidth()
screen_height = help.winfo_screenheight()
center_x = int(screen_width/2 - window_width / 2)
center_y = int(screen_height/2 - window_height / 2)
help.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}')
help.resizable(True, True)
help.attributes('-alpha',1)
help.attributes('-topmost', 1)
ttk.Label(help, wraplength=window_width, background='#EEAABB', text='NDA(Encrypt/Decrypt Application) is a tool, meant to make IT-Security easy for everybody. No nerdy extras or passwords to remember. !Just be sure to NOT lose the .key file! \n\nQUICK HOW TO:\n1a. Select your file you want to encrypt\n2a. Hit encrypt\n\n1b. Select your file you want to decrypt\n2b. Select the keyfile that has been created when encrypting\n3b. Hit Decrypt\n\nQuestions or suggestions? feel free to send me an E-Mail\nby press the E-Mail button below.\nTo view the sourcecode or find a visualized tutorial on how to use this tool press the respective button.'
).pack(ipadx='0', ipady='0')
#textBox = tk.Entry(help)
#textBox.insert(0, "[email protected]")
#textBox.configure(state='readonly', readonlybackground='#ff7b7b', relief='sunken')
#textBox.pack(ipadx='22')
def mailto(recipients, subject, body):
#recipients: string with comma-separated emails (no spaces!)
webbrowser.open("mailto:%s?subject=%s&body=%s" %
(recipients, quote(subject), quote(body)))
body_template = """Hello Flo!
I have the following suggestion/question/problem regarding your NDA tool:
Version Number(bottom right corner of NDA):
My Operating System(Linux, Windows, Mac):"""
def gen():
mailto("[email protected]", "NDA-Tool related", body_template % locals())
def source_code():
webbrowser.open("https://github.com/KDropZ/NDA")
def wiki():
webbrowser.open("https://github.com/KDropZ/NDA/wiki")
mail_button = tk.Button(help, text="E-Mail", fg="#000000", background='#BABAFF', cursor="hand2", font=buttonFont)
mail_button.place(anchor="se", relheight='0.09', relwidth='0.3', relx='0.99', rely='0.99')
mail_button.bind("<Button-1>", lambda e: gen())
code_button = tk.Button(help, text="Sourcecode", fg="#000000", background='#BABAFF', cursor="hand2", font=buttonFont)
code_button.place(anchor="sw", relheight='0.09', relwidth='0.3', relx='0.01', rely='0.99')
code_button.bind("<Button-1>", lambda e: source_code())
wiki_button = tk.Button(help, text="Visualized manual", fg="#000000", background='#BABAFF', cursor="hand2")
wiki_button.place(anchor="s", relheight="0.09", relwidth="0.35", relx="0.5", rely="0.99")
wiki_button.bind("<Button-1>", lambda e: wiki())
help.mainloop()
root.columnconfigure(3, weight=1)
root.rowconfigure(3, weight=1)
buttonFont = font.Font(family='Helvetica', size=12, weight='bold')
tk.Button(root, cursor='hand2', text='Select file to encrypt', bg='#420042', fg='#FFFFFF', command=select_file_en).place(anchor='nw', relx='0.25', rely='0.12', x='0', y='0')
tk.Button(root, cursor='hand2', text='Encrypt file', font=buttonFont, bg='#420042', fg='#FFFFFF', command= lambda: encrypt(en_filename)).place(anchor='nw', relx='0.78', rely='0.12', x='0', y='0')
ttk.Separator(root, orient='horizontal').place(anchor='nw', relheight='0.02', relwidth='1.0', relx='0.0', rely='0.30', y='0') #bg='#ff7b7b'
tk.Button(root, cursor='hand2', text='Select file to decrypt', bg='#420042', fg='#FFFFFF', command=select_file_de).place(anchor='nw', relx='0.25', rely='0.4', x='0', y='0')
tk.Button(root, cursor='hand2', text='Select key', bg='#420042', fg='#FFFFFF', command=select_key).place(anchor='nw', relx='0.57', rely='0.4', x='0', y='0')
tk.Button(root, cursor='hand2', text='Decrypt file', font=buttonFont, bg='#420042', fg='#FFFFFF', command= lambda: decrypt(de_filename, de_key)).place(anchor='nw', relx='0.78', rely='0.4', x='0', y='0')
ttk.Label(root, background='#ff7b7b', text='v 0.3').grid(column='1', row='6')
tk.Button(root, background='#BABAFF', fg='#000000', text='Help', command=openHelpWindow, font=buttonFont).place(anchor="se", relheight='0.09', relwidth='0.2', relx='0.99', rely='0.99') #grid(column='4', row='6')
textBox = tk.Entry(root)
textBox.insert(0, "[email protected]")
textBox.configure(state='readonly', readonlybackground='#ff7b7b', relief='sunken')
textBox.grid(column='3', row='6', ipadx='22')
root.mainloop()