07.07.2023 Views

Implementing-cryptography-using-python

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6 ■ Using Cryptography with Images 193

>>> modfile = ‘stegaudio_dogs.png’

>>> decrypted = ‘decrypted_sample.mp3’

Use the retrieve() method to pull out the media file and write it to a new

file that was specified in the decrypted variable:

>>> secret_bin = crypto_steganography.retrieve(modfile)

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

>>> f.write(secret_bin)

Now we will put it together with a working example that will hide a media

file inside an image of dogs named do gs.jpg. There is nothing special about

this image shown in Figure 6.13. It is simply just a photo of my two dogs taken

with my cell phone camera; it is, however, a large enough file in which to hide

a 700 KB MP3 file.

Figure 6.13: High-definition photo of dogs

The following code will take an MP3 file and hide it inside a large JPG file.

from cryptosteganography import CryptoSteganography

# open sound file

mediafile = 'chapter6/steg/file_example_MP3_700KB.mp3'

message = None

with open(mediafile, "rb") as f:

message = f.read()

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

Saved successfully!

Ooh no, something went wrong!