Skip to content

Commit af95a65

Browse files
working on encryption
1 parent c291f65 commit af95a65

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

one.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from hurry.filesize import size
77
import pyfiglet
88
from cryptography.fernet import Fernet
9+
import base64
10+
911
def warn_md5():
1012
print(f"Warning! MD5s do not match! {sent_hash}/{new_hash}")
1113
print("This means that either the transfer went wrong, or the file ")
@@ -32,9 +34,6 @@ def warn_md5():
3234
print(pyfiglet.figlet_format("A Programmer"))
3335
sys.exit()
3436
if sys.argv[1] == 'transmit':
35-
default_key = '5LabvIZ3MFAxk0IgJnTjwyHbWXVZdoPQcEzLeLL9IHE='.encode()
36-
f = Fernet(default_key)
37-
3837
SEP = "<SEP>"
3938
BUFFER_SIZE = 4096
4039
port = 9001
@@ -52,11 +51,10 @@ def warn_md5():
5251
print(f"[*] Connected to {host}!")
5352
Hash = hashlib.md5(open(filename,'rb').read()).hexdigest()
5453
print(Hash)
55-
dat = f'{filename}{SEP}{filesize}{SEP}{Hash}'
54+
dat = f'{filename}{SEP}{filesize}{SEP}{Hash}{SEP}{Fernet.generate_key().decode("ascii")}'
5655
# while len(dat.encode()) < 4096:
5756
# dat = dat+'0'
58-
data = f.encrypt(dat.encode())
59-
s.send(data.encode())
57+
s.send(dat)
6058

6159

6260
progress = tqdm.tqdm(range(filesize), f'Sending {filename}', unit='B', unit_scale=True, unit_divisor=1024)
@@ -129,7 +127,7 @@ def warn_md5():
129127
s.close()
130128
progress.close()
131129
del f
132-
new_hash = hashlib.md5(open(filename,'rb').read()).hexdigest()
133-
if not new_hash == sent_hash:
134-
warn_md5()
130+
new_hash = hashlib.md5(open(filename,'rb').read()).hexdigest()
131+
if not new_hash == sent_hash:
132+
warn_md5()
135133

0 commit comments

Comments
 (0)