-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtx.py
More file actions
39 lines (24 loc) · 904 Bytes
/
tx.py
File metadata and controls
39 lines (24 loc) · 904 Bytes
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
from Crypto.Cipher import AES
def add_preamble():
preamble = bytes([0b10101010]) * 3000
detect_sequence = b'0011001100110011' # Sequence to detect preamble
with open('output.tmp', 'wb') as output_file:
output_file.write(preamble + detect_sequence + ciphertext + detect_sequence + preamble)
#Encryption
def pad(data):
# Padding the data to be a multiple of 16 bytes
return data + b"\0" * (AES.block_size - len(data) % AES.block_size)
def encrypt_file(file_path, key):
global ciphertext
with open(file_path, 'rb') as file:
plaintext = file.read()
plaintext = pad(plaintext)
cipher = AES.new(key, AES.MODE_ECB)
ciphertext = cipher.encrypt(plaintext)
# Encryption details
file_path = 'images.jpeg'
predefined_key = b'Hello_IamMihiran'
# Encrypt the file
encrypt_file(file_path, predefined_key)
#Adds the preamble
add_preamble()