07.07.2023 Views

Implementing-cryptography-using-python

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

194 Chapter 6 ■ Using Cryptography with Images

print()

print('The program is looking for an image named dogs.jpg\n')

origfile = "chapter6\steg\dogs.jpg"

print('The image with the hidden audio file will be called steg_audio_

dogs.png\n')

modfile = "chapter6\steg\steg_audio_dogs.png"

key = "1111222233334444!"

crypto_steganography = CryptoSteganography(key)

crypto_steganography.hide(origfile, modfile, message)

print('The extracted data will be called decrypted_sample2.mp3 \n')

decrypted = 'decrypted_sample2.mp3'

secret_bin = crypto_steganography.retrieve(modfile)

# Save the data to a new file

with open(decrypted, 'wb') as f:

f.write(secret_bin)

In Figure 6.14, you will see the output from the preceding Python recipe. The

code takes a media file and encrypts it inside the dogs.jpg image. You will see

that the original size of the dogs image is 598 KB. Once you embed the media

file, the outputted file is 4,983 KB. The previous example also extracts the media

file from the image and stores it as decrypted_sample.mp3. You can compare

the two MP3 files; you will find that they are identical.

Figure 6.14: Steganography with media

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!