/
cipherFunctions.py
36 lines (34 loc) · 1.3 KB
/
cipherFunctions.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
from simplecrypt import encrypt, decrypt, DecryptionException
from tkinter import messagebox
def encryptFile(location, name, key):
with open(location, "rb") as unencryptedFile:
byteForm = unencryptedFile.read()
encryptedBytes = encrypt(key, byteForm)
try:
destinationFile = "EncryptedFiles/"+name
encryptedFile = open(destinationFile, "wb")
encryptedFile.write(encryptedBytes)
encryptedFile.close()
return True
except:
print("An error occured writing the encrypted bytes to file")
return False
def decryptFile(location, name, key):
with open(location, "rb") as encryptedFile:
try:
encryptedBytes = encryptedFile.read()
decryptedBytes = decrypt(key, encryptedBytes)
except DecryptionException:
messagebox.showwarning("Error","This file was not encrypted by this group")
return
except:
return False
try:
decryptLocation = "DecryptedFiles/"+name
decryptTarget = open(decryptLocation, "wb")
decryptTarget.write(decryptedBytes)
decryptTarget.close()
return True
except:
print("Error writing to decrypted target file")
return False