-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrx.py
More file actions
57 lines (39 loc) · 1.38 KB
/
rx.py
File metadata and controls
57 lines (39 loc) · 1.38 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
from Crypto.Cipher import AES
# Function to remove both front and back preambles and sequence from file
def remove_preamble(file_path):
global content
detect_sequence = b'0011001100110011'
preamble = bytes([0b10101010]) * 3000
with open(file_path, 'rb') as file:
content = file.read()
start_index = content.find(detect_sequence)
if start_index != -1:
content = content[start_index + len(detect_sequence):]
end_index = content.rfind(detect_sequence)
if end_index != -1:
content = content[:end_index]
preamble_length = len(preamble)
while True:
start_index = content.find(preamble)
if start_index == -1:
break
else:
content = content[start_index + preamble_length:]
while True:
end_index = content.rfind(preamble)
if end_index == -1:
break
else:
content = content[:end_index]
def decrypt_file(key):
ciphertext = content
cipher = AES.new(key, AES.MODE_ECB)
decrypted = cipher.decrypt(ciphertext).rstrip(b'\0') # Removing padding
#Write the decrypted file
with open('decrypted_file', 'wb') as file:
file.write(decrypted)
#Key
predefined_key = b'Hello_IamMihiran'
# Remove both front and back preambles and sequence from the output.tmp file
remove_preamble('output.tmp')
decrypt_file(predefined_key)