{"id":26740,"date":"2022-03-31T02:21:22","date_gmt":"2022-03-30T20:51:22","guid":{"rendered":"https:\/\/python-programs.com\/?p=26740"},"modified":"2022-03-31T02:21:22","modified_gmt":"2022-03-30T20:51:22","slug":"image-based-steganography-using-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/image-based-steganography-using-python\/","title":{"rendered":"Image Based Steganography using Python"},"content":{"rendered":"
What is Steganography?<\/strong><\/p>\n Steganography is the process of hiding a secret message within a larger one in such a way that the presence or contents of the hidden message are unknown. The goal of steganography is to keep communication between two parties hidden. Unlike cryptography, which allows us to hide the content of a secret message, Steganography hides the fact that a message has been sent. Despite the fact that Steganography and Cryptography are not the same, there are some parallels between the two. Steganography is classified as a type of cryptography by some writers since hidden communication appears to be a secret message.<\/p>\n Steganography is the process of hiding confidential data within an ordinary file during transmission. Secret data and ordinary files can both take the form of a text message, image, audio clip, or video file. A simple example of hiding a text message within an image is provided below. The two main steps are as follows:<\/p>\n Encryption<\/strong> is the process of storing a text message within an image.<\/p>\n Decryption<\/strong> is the process of extracting the message hidden within an image.<\/p>\n Before going to the coding part we should first install the pillow and stepic libraries into our system<\/p>\n Installation:<\/strong><\/p>\n Output:<\/strong><\/p>\n pillow module in Python:<\/strong><\/p>\n Pillow is a Python Imaging Library (PIL) that allows you to open, manipulate, and save images in a variety of formats.<\/p>\n stepic module in Python:<\/strong> 1)Encryption<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n <\/p>\n As seen in the preceding image, the original image and the image acquired after encryption appears identical. The secret text message hiding within the latter image is not apparent to us, nor does this image appear altered in terms of pixel intensities to the human eye.<\/p>\n 2)Decryption\u00a0<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n What is Steganography? Steganography is the process of hiding a secret message within a larger one in such a way that the presence or contents of the hidden message are unknown. The goal of steganography is to keep communication between two parties hidden. Unlike cryptography, which allows us to hide the content of a secret …<\/p>\n
\nImage steganography is the practice of hiding sensitive data within an image or video file.<\/p>\npip\u00a0install\u00a0Pillow<\/pre>\n
pip\u00a0install\u00a0stepic<\/pre>\n<\/div>\n<\/div>\n<\/div>\n
Collecting stepic\r\nDownloading stepic-0.5.0.tar.gz (219 kB)\r\n|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 219 kB 4.1 MB\/s \r\nRequirement already satisfied: pillow in \/usr\/local\/lib\/python3.7\/\r\ndist-packages\r\n (from stepic) (7.1.2)\r\nBuilding wheels for collected packages: stepic\r\nBuilding wheel for stepic (setup.py) ... done\r\nCreated wheel for stepic: filename=stepic-0.5.0-py3-none-any.whl size=12428\r\n sha256=bcf777c1de2853e6fd38c63e0ba14b7d95c6803aebac77f72f18752979b216a2\r\nStored in directory: \/root\/.cache\/pip\/wheels\/47\/8d\/57\/322e721ace59cf72d3282\r\n42bbc636e6affc672344cf5480f33\r\nSuccessfully built stepic\r\nInstalling collected packages: stepic\r\nSuccessfully installed stepic-0.5.0<\/pre>\n
\nstepic is a Python package for hiding data within an image by slightly altering the image’s colors. These changes are normally unnoticeable to the naked eye, but they are detectable by machines.<\/p>\nImage-Based Steganography using Python<\/h2>\n
\n
# Import Image from PIL module using the import keyword\r\nfrom PIL import Image\r\n# Import stepic module using the import keyword\r\nimport stepic\r\n\r\n# Open the image using the open() function of the Image module \r\n# by passing the image filename\/path as an argument to it\r\n# in which the secret message will be stored.\r\ngvn_image = Image.open(\"sampleimage.jpg\")\r\n# Give some random secret message and store it in a variable\r\nsecret_msg = \"Welcome to Python-programs\"\r\n# Convert the above given secret message into UTF-8 format using the encode() function\r\n# and store it in the same variable\r\nsecret_msg = secret_msg.encode()\r\n# Pass the given image and secret message into the encode() function of the stepic module\r\n# which gives a new image within which the secret message is hidden.\r\nencodedimage = stepic.encode(gvn_image, secret_msg)\r\n# Save the above encoded\/encrypted image with some random name and extension using the \r\n# save() function\r\nencodedimage.save(\"EncryptedImage.png\")\r\n# Print some random text for acknowledgment\r\nprint(\"Encryption has done successfully\")<\/pre>\n
Encryption has done successfully<\/pre>\n
\n
# Import Image from PIL module using the import keyword\r\nfrom PIL import Image\r\n# Import stepic module using the import keyword\r\nimport stepic\r\n\r\n# Open the image from which you want to extract the secret message(encrypted image) using the\r\n# open() function by passing filename\/path as an argument to it.\r\n# Store it in a variable\r\nencryptd_image = Image.open(\"EncryptedImage.png\")\r\n\r\n# Pass the above encrypted image to the decode() function of the stepic module \r\n# to give the encrypted secret message in the string format.\r\n# Store it in another variable\r\ndecryptedmessage = stepic.decode(encryptd_image)\r\n# Print some random text for acknowledgment\r\nprint(\"Decryption has done successfully\")\r\n# Print the decrypted\/decoded message\r\nprint(\"The decrypted message = \", decryptedmessage)<\/pre>\n
Decryption has done successfully\r\nThe decrypted message = Welcome to Python-programs<\/pre>\n","protected":false},"excerpt":{"rendered":"