-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecoder multiple.py
46 lines (40 loc) · 1.34 KB
/
decoder multiple.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
37
38
39
40
41
42
43
44
45
46
from Crypto.Cipher import Blowfish
from Crypto import Random
import struct
from PIL import Image
import stegano.lsb as lsb
def read_key():
"""
Read the key from the file called key.txt
"""
with open('key.txt', 'rb') as f:
key = f.read()
return key
def decrypt(ciphertext):
"""
Decrypt the ciphertext using the Blowfish algorithm with the key read from the file.
Returns the decrypted plaintext.
"""
# Extract the IV from the ciphertext
iv = ciphertext[:Blowfish.block_size]
# Create the cipher object and decrypt the ciphertext
cipher = Blowfish.new(read_key(), Blowfish.MODE_CBC, iv)
plaintext = unpad(cipher.decrypt(ciphertext[Blowfish.block_size:]))
# Return the decrypted plaintext
return plaintext
def pad(s):
"""
Pad the given string s with zeros to a multiple of the block size.
"""
if isinstance(s, str):
s = s.encode()
return s + (Blowfish.block_size - len(s) % Blowfish.block_size) * bytes([0])
def unpad(s):
"""
Remove the zero padding from the given string s.
"""
return s.rstrip(bytes([0]))
image = Image.open(r'C:\Users\aimem\OneDrive\Desktop\CODE OF HONOUR\encoded_image.png')
ciphertext = lsb.reveal(image)
decrypted_plaintext = decrypt(ciphertext)
print(decrypted_plaintext.decode())