-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheceis.py
368 lines (290 loc) · 12.7 KB
/
eceis.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# Core Packages
import tkinter as tk
from tkinter import *
from tkinter import ttk #for tab creation using tkinter
from tkinter.scrolledtext import *
import tkinter.filedialog
# Other pkg
import time
timestr = time.strftime("%Y%m%d-%H%M%S")
# NLP Pkgs
from spacy_summarization import text_summarizer
from gensim.summarization import summarize
from nltk_summarization import nltk_summarizer
from sumy.parsers.plaintext import PlaintextParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.summarizers.lex_rank import LexRankSummarizer
# Web Scraping Pkg
from bs4 import BeautifulSoup
from urllib.request import urlopen
#packages for ECIES
from ecies.utils import generate_eth_key
from ecies import encrypt, decrypt
import binascii
def sumy_summary(docx):
parser = PlaintextParser.from_string(docx, Tokenizer("english"))
lex_summarizer = LexRankSummarizer()
summary = lex_summarizer(parser.document, 3)
summary_list = [str(sentence) for sentence in summary]
result=''.join(summary_list)
return result
# Structure and Layout
window = Tk()
window.title("Encryption/Decryption using ECIES")
window.geometry("950x750")
window.config(background='black')
style = ttk.Style(window)
style.configure('lefttab.TNotebook', tabposition='wn') #tabs positioned west-north
# TAB LAYOUT
tab_control = ttk.Notebook(window,style='lefttab.TNotebook')
tab1 = ttk.Frame(tab_control)
tab2 = ttk.Frame(tab_control)
tab3 = ttk.Frame(tab_control)
tab4 = ttk.Frame(tab_control)
tab5 = ttk.Frame(tab_control)
tab6 = ttk.Frame(tab_control)
# ADD TABS TO NOTEBOOK
tab_control.add(tab1, text=f'{"Home":^40s}')
tab_control.add(tab3, text=f'{"Plain Text":^39s}')
tab_control.add(tab4, text=f'{"File Upload":^37s}')
tab_control.add(tab5, text=f'{"URL analysis":^36s}')
label1 = Label(tab1, text= 'About',padx=5, pady=5)
label1.grid(column=1, row=0, pady=5)
label3 = Label(tab3, text= 'Plain text summarisation and Ecryption/Decryption',padx=5, pady=5)
label3.grid(column=1, row=0, pady=5)
label4 = Label(tab4, text= 'File summarisation and Ecryption/Decryption',padx=5, pady=5)
label4.grid(column=1, row=0, pady=5)
label5 = Label(tab5, text= 'URL summarisation and Ecryption/Decryption',padx=5, pady=5)
label5.grid(column=1, row=0, pady=5)
tab_control.pack(expand=1, fill='both')
######
# Functions for candidate information tab
def get_summary():
raw_text = str(entry.get('1.0',tk.END))
final_text = text_summarizer(raw_text)
print(final_text)
result = '\nSummary:{}'.format(final_text)
tab3_display.insert(tk.END,result)
def clear_text():
entry.delete('1.0',END)
def clear_display_result():
tab3_display.delete('1.0',END)
def save_summary():
raw_text = str(tab3_display.get('1.0',tk.END))
final_text = text_summarizer(raw_text)
file_name = 'File_'+ timestr + '.txt'
with open(file_name, 'w') as f:
f.write(final_text)
result = '\nName of file: {}'.format(file_name)
tab3_display.insert(tk.END,result)
############################################
def encrypt_text():
raw_text = str(entry.get('1.0',tk.END))
raw_text= bytes(raw_text,'utf-8')
privKey = generate_eth_key()
privKeyHex = privKey.to_hex()
pubKeyHex = privKey.public_key.to_hex()
encrypted = encrypt(pubKeyHex, raw_text)
encrypted = binascii.hexlify(encrypted)
result = 'Encrypted text:\n{}'.format(encrypted)
tab3_display.insert(tk.END,result)
result1 = '{}'.format(privKeyHex)
tab3_display1.insert(tk.END,result1)
def decrypt_text():
encrypted = str(entry.get('1.0',tk.END))
encrypted= bytes(encrypted,'utf-8').strip()
encrypted = binascii.unhexlify(encrypted)
privKeyHex= str(tab3_display1.get('1.0',tk.END)).strip()
decrypted = decrypt(privKeyHex, encrypted)
result = 'Decrypted text:\n{}'.format(decrypted)
tab3_display.insert(tk.END,result)
#####
#Functions for File tab
def openfiles():
file1 = tkinter.filedialog.askopenfilename(filetypes=(("Text Files",".txt"),("All files","*")))
read_text = open(file1).read()
displayed_file.insert(tk.END,read_text)
# for reset button
def clear_text_file():
displayed_file.delete('1.0',END)
# Clear Result of Functions
def clear_text_result():
tab4_display_text.delete('1.0',END)
def get_file_summary():
raw_text = displayed_file.get('1.0',tk.END)
final_text = text_summarizer(raw_text)
result = '\nSummary:{}'.format(final_text)
tab4_display_text.insert(tk.END,result)
def save_summary1():
raw_text = str(tab4_display_text.get('1.0',tk.END))
final_text = text_summarizer(raw_text)
file_name = 'File_'+ timestr + '.txt'
with open(file_name, 'w') as f:
f.write(final_text)
result = '\nName of file: {}'.format(file_name)
tab4_display_text.insert(tk.END,result)
############################################
def encrypt_file():
raw_text = str(displayed_file.get('1.0',tk.END))
raw_text= bytes(raw_text,'utf-8')
privKey = generate_eth_key()
privKeyHex = privKey.to_hex()
pubKeyHex = privKey.public_key.to_hex()
encrypted = encrypt(pubKeyHex, raw_text)
encrypted = binascii.hexlify(encrypted)
result = 'Encrypted text:\n{}'.format(encrypted)
tab4_display_text.insert(tk.END,result)
result1 = '{}'.format(privKeyHex)
tab4_display1.insert(tk.END,result1)
def decrypt_file():
encrypted = str(displayed_file.get('1.0',tk.END))
encrypted= bytes(encrypted,'utf-8').strip()
encrypted = binascii.unhexlify(encrypted)
privKeyHex= str(tab4_display1.get('1.0',tk.END)).strip()
decrypted = decrypt(privKeyHex, encrypted)
result = 'Decrypted text:\n{}'.format(decrypted)
tab4_display_text.insert(tk.END,result)
#####
#Functions for Candidate URL TAB
def clear_url_entry():
url_entry.delete(0,END)
def clear_url_display():
tab5_display_text.delete('1.0',END)
# Fetch Text From Url
def get_text():
raw_text = str(url_entry.get())
page = urlopen(raw_text)
soup = BeautifulSoup(page)
fetched_text = ' '.join(map(lambda p:p.text,soup.find_all('p')))
url_display.insert(tk.END,fetched_text)
def get_url_summary():
raw_text = url_display.get('1.0',tk.END)
final_text = text_summarizer(raw_text)
result = '\nSummary:{}'.format(final_text)
tab5_display_text.insert(tk.END,result)
def save_summary2():
raw_text = str(tab5_display_text.get('1.0',tk.END))
final_text = text_summarizer(raw_text)
file_name = 'File_'+ timestr + '.txt'
with open(file_name, 'w') as f:
f.write(final_text)
result = '\nName of file: {}'.format(file_name)
tab5_display_text.insert(tk.END,result)
############################################
def encrypt_url():
raw_text = str(url_display.get('1.0',tk.END))
raw_text= bytes(raw_text,'utf-8')
privKey = generate_eth_key()
privKeyHex = privKey.to_hex()
pubKeyHex = privKey.public_key.to_hex()
encrypted = encrypt(pubKeyHex, raw_text)
encrypted = binascii.hexlify(encrypted)
result = 'Encrypted text:\n{}'.format(encrypted)
tab5_display_text.insert(tk.END,result)
result1 = '{}'.format(privKeyHex)
tab5_display1.insert(tk.END,result1)
def decrypt_url():
encrypted = str(url_display.get('1.0',tk.END))
encrypted= bytes(encrypted,'utf-8').strip()
encrypted = binascii.unhexlify(encrypted)
privKeyHex= str(tab5_display1.get('1.0',tk.END)).strip()
decrypted = decrypt(privKeyHex, encrypted)
result = 'Decrypted text:\n{}'.format(decrypted)
tab5_display_text.insert(tk.END,result)
################# Home tab
about_label = Label(tab1,text="Our Project:\n\nEncryption/Decryption using ECIES",pady=5,padx=5)
about_label.grid(column=1,row=1, pady=5)
about_label = Label(tab1,text="Made By:\n1. Ritika Kayal - 18BCE2518\n2. Srinivas\n3. Amritanshi",pady=5,padx=5)
about_label.grid(column=1,row=2, pady=5)
about_label = Label(tab1,text="Abstract:\n With the rise of the internet, it has become more and more common for important, \ncritical documents to be shared through electronic means. \nThis means that it has become essential that documents and important \ndetails be kept confidential through the means of encryption. \nECC has risen in popularity and is dubbed “The Successor to RSA” \nas it is capable of achieving the same security of a 1024 bit RSA key \nwith just 208 bits. \nThus, it is the most optimal method for securing data against breaches and unauthorized access. \nDocuments have also grown in size over time \nas more detail can be stored due to larger and faster storage availability. \nExcessive amounts of time is wasted on reading filler and unnecessary content in documents \nto understand them and this becomes an issue as it limits the productivity of an individual. \nSkimming through large documents may also lead to users missing important details. \nHence a smart Natural Language Processing system that can parse through \ndocuments / text file / URLs can help save precious time \nwhile also conveying all the important facts/details needed.",pady=5,padx=5)
about_label.grid(column=1,row=3, pady=5)
#BUTTONS
b0=Button(tab1,text="Close", width=12,command=window.destroy)
b0.grid(row=4,column=1,padx=10,pady=10)
##################### Plain text Tab
l1=Label(tab3,text="Enter Text")
l1.grid(row=2,column=1)
entry=ScrolledText(tab3,height=8)
entry.grid(row=3,column=0,columnspan=4,padx=5,pady=5)
button1=Button(tab3,text="Reset",command=clear_text, width=12)
button1.grid(row=4,column=0,padx=10,pady=10)
button2=Button(tab3,text="Summarize",command=get_summary, width=12)
button2.grid(row=4,column=2,padx=10,pady=10)
button5=Button(tab3,text="Encrypt", command=encrypt_text, width=12)
button5.grid(row=5,column=0,padx=10,pady=10)
button6=Button(tab3,text="Decrypt", command=decrypt_text, width=12)
button6.grid(row=5,column=2,padx=10,pady=10)
l1=Label(tab3,text="Decryption private key")
l1.grid(row=6,column=1)
tab3_display1 = ScrolledText(tab3, height=1)
tab3_display1.grid(row=7,column=0, columnspan=3,padx=5,pady=5)
l1=Label(tab3,text="Output")
l1.grid(row=8,column=1)
tab3_display = ScrolledText(tab3, height=8)
tab3_display.grid(row=9,column=0, columnspan=3,padx=5,pady=5)
button3=Button(tab3,text="Clear Result", command=clear_display_result, width=12)
button3.grid(row=10,column=2,padx=10,pady=10)
button4=Button(tab3,text="Save", command=save_summary, width=12)
button4.grid(row=10,column=0,padx=10,pady=10)
###################### File summarisation
l1=Label(tab4,text="Open File To Summarize")
l1.grid(row=1,column=1)
displayed_file = ScrolledText(tab4,height=8)
displayed_file.grid(row=2,column=0, columnspan=3,padx=5,pady=5)
b0=Button(tab4,text="Open File", width=12, command=openfiles)
b0.grid(row=3,column=0,padx=10,pady=10)
b2=Button(tab4,text="Summarize", width=12,command=get_file_summary)
b2.grid(row=3,column=2,padx=10,pady=10)
button5=Button(tab4,text="Encrypt", command=encrypt_file, width=12)
button5.grid(row=4,column=0,padx=10,pady=10)
button6=Button(tab4,text="Decrypt", command=decrypt_file, width=12)
button6.grid(row=4,column=2,padx=10,pady=10)
l1=Label(tab4,text="Decryption private key")
l1.grid(row=5,column=1)
tab4_display1 = ScrolledText(tab4, height=1)
tab4_display1.grid(row=6,column=0, columnspan=3,padx=5,pady=5)
l1=Label(tab4,text="Output")
l1.grid(row=7,column=1)
# Display Screen
tab4_display_text = ScrolledText(tab4,height=8)
tab4_display_text.grid(row=8,column=0, columnspan=3,padx=5,pady=5)
# Allows you to edit
tab4_display_text.config(state=NORMAL)
b1=Button(tab4,text="Reset", width=12,command=clear_text_file)
b1.grid(row=9,column=0,padx=10,pady=10)
b5=Button(tab4,text="Save", command=save_summary1, width=12)
b5.grid(row=9,column=1,padx=10,pady=10)
b3=Button(tab4,text="Clear Result", width=12,command=clear_text_result)
b3.grid(row=9,column=2,padx=10,pady=10)
# URL TAB
l1=Label(tab5,text="Enter URL To Summarize")
l1.grid(row=1,column=0)
raw_entry=StringVar()
url_entry=Entry(tab5,textvariable=raw_entry,width=30)
url_entry.grid(row=1,column=1)
button2=Button(tab5,text="Get Text",command=get_text, width=12,bg='#03A9F4')
button2.grid(row=1,column=2,padx=10,pady=10)
# Display Screen For URL text
url_display = ScrolledText(tab5,height=8)
url_display.grid(row=2,column=0, columnspan=3,padx=5,pady=5)
button1=Button(tab5,text="Reset",command=clear_url_entry, width=12,bg='#03A9F4')
button1.grid(row=3,column=0,padx=10,pady=10)
button4=Button(tab5,text="Summarize",command=get_url_summary, width=12,bg='#03A9F4')
button4.grid(row=3,column=2,padx=10,pady=10)
button5=Button(tab5,text="Encrypt", command=encrypt_url, width=12)
button5.grid(row=4,column=0,padx=10,pady=10)
button6=Button(tab5,text="Decrypt", command=decrypt_url, width=12)
button6.grid(row=4,column=2,padx=10,pady=10)
l=Label(tab5,text="Decryption private key")
l.grid(row=5,column=1)
tab5_display1 = ScrolledText(tab5, height=1)
tab5_display1.grid(row=6,column=0, columnspan=3,padx=5,pady=5)
l1=Label(tab5,text="Output")
l1.grid(row=7,column=1)
tab5_display_text = ScrolledText(tab5,height=8)
tab5_display_text.grid(row=8,column=0, columnspan=3,padx=5,pady=5)
button3=Button(tab5,text="Clear Result", command=clear_url_display,width=12,bg='#03A9F4')
button3.grid(row=9,column=0,padx=10,pady=10)
b5=Button(tab5,text="Save", command=save_summary2, width=12)
b5.grid(row=9,column=2,padx=10,pady=10)
window.mainloop()