Today, we are gonna learn how to apply coding skills to , by performing image-based which hiding involves secret messages in an image. Stenography has been used for quite a while. Since World War II, it was heavily used for communication among allies so as to prevent the info being captured by enemies cryptography stenography I will guide you to how to do using two different techniques, one involving a secret key and one that doesn’t. Requirements Stegano Steganocryptopy Installation pip install steganocryptopy pip install stegano Image stenography without Key Here will be hiding our hiding text within an image without any encryption key, therefore the recipient of the image is able to decrypt and get the hidden text instantly without any key. Pros: The advantage of this is simple since you’re not going to deal any memorized key issues. Cons: Anyone can decrypt as long as he uses the same library you used during encryption. Encrypting text into an image Syntax stegano lsb secret = lsb.hide(path_to_img, secret_msg) secret.save(ecrypted_img_name) from import You’re supposed to have a sample image on your project folder to hide the message, we are gonna provide a path to our image to our encryption library. Example of Usage >>> stegano lsb >>> secret = lsb.hide( , ) >>> secret.save( ) from import "sample.png" "Python is dangerous be careful" "sample_secret.png" Now if you look at the project folder you will realize there is a new image with the name There nothing which can tell you it consists of a hidden msg. sample_secret.png. Decrypting text from an image Make sure the image with hidden text is in your project folder. Syntax >>> stegano lsb >>>lsb.reveal(path_to_an_image) from import Usage >>> stegano lsb >>>lsb.reveal( ) from import 'sample_secret.png' 'Python is dangerous be careful' Well that’s it , now let’s dive into hiding into image with a secret key Image stenography with Secret Key Here we will be hiding our secret text in the message together with an encryption key required to decode it. Therefore, only the one with the secret key is able decode it. Pros: It’s much secure since only those with a secret key can decrypt it. Cons: Once the encryption key is lost, it complicates the decryption process. Syntax >>> steganocryptopy.steganography Steganography >>> Steganography.generate_key(path_to_key) >>> encrypted = Steganography.encrypt(path_to_key, path_to_img, path_to_secretfile) >>> encrypted.save(encrypted_imgname) from import Usage Let’s assume I have a file containing my secret key named , a file consisting of our hidden message named , and our raw image named key classified.us sample.png >>> steganocryptopy.steganography Steganography >>> Steganography.generate_key( ) >>> encrypted = Steganography.encrypt( , , ) >>> encrypted.save( ) from import "key" "key" "sample.png" "classified.us" "Secret.png" Now once you run the above code you should see a new image on your project folder named consisting secret message. Secret.png Decryption of the Message To decrypt the image, you will need a file containing a and your key encrypted image Syntax >>> steganocryptopy.steganography Steganography >>> Steganography.decrypt(path_to_key, path_to_image) from import Usage >>> steganocryptopy.steganography Steganography >>> Steganography.decrypt( , ) from import "key" "Secret_img.png" 'Life is short you need Python\n' Congratulations, you have just learned how to hide secret messages in the image, Now don’t be shy to share messages with your friends. In case of any comment, suggestion, create a thread in community and I will get back to you as fast as possible. Don’t forget to subscribe to this blog post to be notified when a new cool tutorial is out Previously published at https://kalebujordan.com/image-stenography-in-python/