-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecryption.py
More file actions
58 lines (42 loc) · 1.49 KB
/
decryption.py
File metadata and controls
58 lines (42 loc) · 1.49 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
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
def decrypt(key):
# open file
file1 = open('manager.bin', 'r')
Lines = file1.readlines()
resultList = []
for f in Lines:
read_line = f.strip('\n')
split_list = delimiter(read_line)
result = decode(split_list, key)
if result:
print("The message in the file was:", result)
resultList.append(result)
return resultList
def delimiter(line):
# Split the line into a list
splitWords = line.split('|')
splitWords.pop(0)
return splitWords
def decode(lst, key):
key = key.encode('utf-8')
final_list = []
for item in lst:
try:
# Convert the string to byte array
encrypted_data = eval(item)
# Set up the AES decryption cipher
dec_cipher = AES.new(key, AES.MODE_ECB)
# Decrypt the data
decrypted_data = dec_cipher.decrypt(encrypted_data)
# Remove padding from the decrypted data
unpadded_data = unpad(decrypted_data, AES.block_size)
# Append data to the end of the list
final_list.append(unpadded_data.decode('utf-8')) # Convert the bytes back to a string
except Exception as e:
print("Error decrypting data:", e)
return False
return final_list
if __name__ == '__main__':
key = str(input("Please enter a key (Leave blank for default key): "))
decrypt(key)