Image Steganography in Cryptography
Last Updated :
22 Aug, 2023
The word Steganography is derived from two Greek words- ‘stegos’ meaning ‘to cover’ and ‘grayfia’, meaning ‘writing’, thus translating to ‘covered writing’, or ‘hidden writing’. Steganography is a method of hiding secret data, by embedding it into an audio, video, image, or text file. It is one of the methods employed to protect secret or sensitive data from malicious attacks.
How is it different from cryptography?
Cryptography and steganography are both methods used to hide or protect secret data. However, they differ in the respect that cryptography makes the data unreadable, or hides the meaning of the data, while steganography hides the existence of the data.
In layman’s terms, cryptography is similar to writing a letter in a secret language: people can read it, but won’t understand what it means. However, the existence of a (probably secret) message would be obvious to anyone who sees the letter, and if someone either knows or figures out your secret language, then your message can easily be read.
If you were to use steganography in the same situation, you would hide the letter inside a pair of socks that you would be gifting the intended recipient of the letter. To those who don’t know about the message, it would look like there was nothing more to your gift than the socks. But the intended recipient knows what to look for, and finds the message hidden in them.
Similarly, if two users exchanged media files over the internet, it would be more difficult to determine whether these files contain hidden messages than if they were communicating using cryptography.
Cryptography is often used to supplement the security offered by steganography. Cryptography algorithms are used to encrypt secret data before embedding it into cover files.
Image Steganography –
As the name suggests, Image Steganography refers to the process of hiding data within an image file. The image selected for this purpose is called the cover image and the image obtained after steganography is called the stego image.
How is it done?
An image is represented as an N*M (in case of grayscale images) or N*M*3 (in case of color images) matrix in memory, with each entry representing the intensity value of a pixel. In image steganography, a message is embedded into an image by altering the values of some pixels, which are chosen by an encryption algorithm. The recipient of the image must be aware of the same algorithm in order to know which pixels he or she must select to extract the message.

Figure – Process of Image Steganography
Is steganography a secure method of communication?
When steganography is employed alone, it is security by obscurity, which might result in the secret message being disclosed. Combining steganography and cryptography is the greatest way to disguise a message from adversaries while still protecting it in case it is detected.
In steganography, what algorithm is used?
His steganography approach entails concealing a huge amount of data (picture, audio, and text) within a colour bitmap (bmp) image. The image will be filtered and segmented in his study, with bits replacement applied to the appropriate pixels. These pixels are chosen at random rather than in order.
Detection of the message within the cover image is done by the process of steganalysis. This can be done through comparison with the cover image, histogram plotting, or noise detection. While efforts are being invested in developing new algorithms with a greater degree of immunity against such attacks, efforts are also being devoted towards improving existing algorithms for steganalysis, to detect the exchange of secret information between terrorists or criminal elements.
Here’s an example of how image steganography can be implemented using Python and the ‘PIL' (Python Imaging Library) library:
1. Install the required libraries:
Open a command-line interface (CLI) or terminal.
Run the following command to install the ‘PIL' library:
pip install pillow
2. Import the required libraries:
3. Define the functions for hiding and extracting the secret data:
Python
def hide_text(image_path, secret_text, output_path):
image = Image.open(image_path)
binary_secret_text = ''.join(format(ord(char), '08b') for char in secret_text)
image_capacity = image.width * image.height * 3
if len(binary_secret_text) > image_capacity:
raise ValueError("Image does not have sufficient capacity to hide the secret text.")
pixels = image.load()
index = 0
for i in range(image.width):
for j in range(image.height):
r, g, b = pixels[i, j]
if index < len(binary_secret_text):
r = (r & 0xFE) | int(binary_secret_text[index])
index += 1
if index < len(binary_secret_text):
g = (g & 0xFE) | int(binary_secret_text[index])
index += 1
if index < len(binary_secret_text):
b = (b & 0xFE) | int(binary_secret_text[index])
index += 1
pixels[i, j] = (r, g, b)
image.save(output_path)
def extract_text(image_path):
image = Image.open(image_path)
pixels = image.load()
binary_secret_text = ""
for i in range(image.width):
for j in range(image.height):
r, g, b = pixels[i, j]
binary_secret_text += str(r & 1)
binary_secret_text += str(g & 1)
binary_secret_text += str(b & 1)
secret_text = ""
for i in range(0, len(binary_secret_text), 8):
char = chr(int(binary_secret_text[i:i+8], 2))
secret_text += char
return secret_text
|
4. Hide secret text in an image:
Python
image_path = 'image.jpg'
secret_text = 'This is a secret message.'
output_path = 'output_image.jpg'
hide_text(image_path, secret_text, output_path)
|
5. Extract the secret text from the image:
Python
extracted_text = extract_text(output_path)
print("Extracted text:", extracted_text)
|
In this example, we first convert the secret text into binary form. We then modify the least significant bit of each color channel (red, green, and blue) of the image pixels to store the binary representation of the secret text. To extract the secret text, we retrieve the least significant bit of each color channel and convert it back to ASCII characters.
Some of the features of image steganography in cryptography are:
Secrecy: The primary feature of image steganography is secrecy. The secret information is hidden within the image in a way that is not easily detectable by an unauthorized person.
Capacity: The capacity of an image to carry secret information depends on the size of the image and the amount of information to be hidden. Generally, larger images have a higher capacity to carry secret information.
Robustness: The image steganography technique should be robust, i.e., it should be able to withstand image processing techniques like compression, cropping, and resizing without affecting the hidden information.
Security: The security of the hidden information is of utmost importance. The image steganography technique should be designed in such a way that it is resistant to attacks like statistical analysis and brute force attacks.
Efficiency: The image steganography technique should be efficient, i.e., it should be able to hide the secret information in the image quickly and effectively.
Concealment: The hidden information should be concealed in the image in a way that it is not easily distinguishable from the original image.
Retrieval: The hidden information should be retrievable by the authorized party using a decryption key or algorithm.
Advantages of Image Steganography:
Security: Image steganography provides a high level of security for secret communication as it hides the secret message within the image, making it difficult for an unauthorized person to detect it.
Capacity: Image steganography has a high capacity to carry secret information as it can hide a large amount of data within an image.
Covert Communication: Image steganography provides a covert means of communication, as the existence of the secret message is hidden within the image.
Robustness: Steganography techniques are often designed to be robust, meaning that the hidden message can remain intact even when the image undergoes common image processing operations like compression or resizing.
Resistance to Cryptanalysis: Steganography can make it difficult for cryptanalysts to detect and analyze hidden messages as the message is camouflaged within the image, making it difficult to separate from the image’s natural features.
Disadvantages of Image Steganography:
Detection: Steganography can be detected if a person has the right tools and techniques, so it is not a foolproof method of securing communication.
Complexity: Steganography can be complex and requires specialized tools and knowledge to implement effectively.
Lengthy Transmission Time: Hiding data within an image can be a time-consuming process, especially for large files, which can slow down the transmission of data.
Susceptibility to Data Loss: The hidden message may be lost or distorted during the transmission or processing of the image, resulting in a loss of data.
Misuse: Steganography can be misused for illegal activities, including hiding malicious code or malware within an image, making it difficult to detect and prevent cybersecurity attacks.
Similar Reads
Cryptography Tutorial
Cryptography is a technique of securing communication by converting plain text into unintelligible ciphertext. It involves various algorithms and protocols to ensure data confidentiality, integrity, authentication, and non-repudiation. The two primary types of cryptography are symmetric key cryptogr
7 min read
What is data encryption?
What is Data Encryption?
Data encryption is the process of converting readable information (plaintext) into an unreadable format (ciphertext) to protect it from unauthorized access. It is a method of preserving data confidentiality by transforming it into ciphertext, which can only be decoded using a unique decryption key p
10 min read
Encryption, Its Algorithms And Its Future
Encryption is very important in today's world, it is the process of transforming plaintext into ciphertext to maintain data security, and it is a crucial tool used in modern cyber security. It secures sensitive data by rendering it unreadable to unauthorized events, making sure of confidentiality, i
6 min read
SHA-1 Hash
SHA-1 or Secure Hash Algorithm 1 is a cryptographic algorithm that takes an input and produces a 160-bit (20-byte) hash value. This hash value is known as a message digest. This message digest is usually then rendered as a hexadecimal number which is 40 digits long. It is a U.S. Federal Information
7 min read
RC4 Encryption Algorithm
RC4 is a stream cipher and variable-length key algorithm. This algorithm encrypts one byte at a time (or larger units at a time). A key input is a pseudorandom bit generator that produces a stream 8-bit number that is unpredictable without knowledge of the input key, The output of the generator is c
6 min read
Hash Functions in System Security
Hash Function is a function that has a huge role in making a System Secure as it converts normal data given to it as an irregular value of fixed length. We can imagine it to be a Shaker in our homes. When we put data into this function it outputs an irregular value. The Irregular value it outputs is
4 min read
Blowfish Algorithm with Examples
Blowfish is an encryption technique designed by Bruce Schneier in 1993 as an alternative to DES Encryption Technique. It is significantly faster than DES and provides a good encryption rate with no effective cryptanalysis technique found to date. It is one of the first, secure block cyphers not subj
15+ min read
Difference between MD5 and SHA1
MD5 stands for Message Digest and SHA1 stands for Secure Hash Algorithm both are cryptographic hash algorithms used for security purposes. SHA-1 or Secure Hash Algorithm 1 is a cryptographic algorithm that takes an input and produces a 160-bit (20-byte) hash value. This hash value is known as a mess
5 min read
Difference between RSA algorithm and DSA
In cryptography, the two commonly used algorithms in modern cryptography for secure data transmission and to ensure the signatures of digital signatures, are the Rivest-Shamir-Adleman (RSA) algorithm and Digital Signature Algorithm (DSA). We'll learn about RSA and DSA, how they work when are they us
8 min read
Classical Encryption Techniques
Block Cipher , DES and AES
Public Key Cryptography and RSA
Comman Cryptography
Custom Building Cryptography Algorithms (Hybrid Cryptography)
Cryptography can be defined as an art of encoding and decoding the patterns (in the form of messages). Cryptography is a very straightforward concept which deals with manipulating the strings (or text) to make them unreadable for the intermediate person. It has a very effective way to encrypt or dec
15+ min read
An Overview of Cloud Cryptography
Cloud cryptography is a set of techniques used to secure data stored and processed in cloud computing environments. It provides data privacy, data integrity, and data confidentiality by using encryption and secure key management systems. Common methods used in cloud cryptography include: Symmetric e
4 min read
Quantum Cryptography
The uncertainty principle of quantum physics builds the earliest foundations for quantum cryptography. With quantum computers of the future being expected to solve discrete logarithmic problems and the popularly known cryptography methods such as AES, RSA, DES, quantum cryptography becomes the fores
7 min read
Image Steganography in Cryptography
The word Steganography is derived from two Greek words- 'stegos' meaning 'to cover' and 'grayfia', meaning 'writing', thus translating to 'covered writing', or 'hidden writing'. Steganography is a method of hiding secret data, by embedding it into an audio, video, image, or text file. It is one of t
8 min read
DNA Cryptography
Cryptography is the branch of science that deals with the encoding of information to hide messages. It plays a vital role in the infrastructure of communication security. The Pioneering work had been done by Ashish Gehani et al and Amin et al after Leonard Max Adleman had shown the capability of mol
13 min read
Caesar Cipher in Cryptography
The Caesar Cipher is one of the simplest and oldest methods of encrypting messages, named after Julius Caesar, who reportedly used it to protect his military communications. This technique involves shifting the letters of the alphabet by a fixed number of places. For example, with a shift of three,
12 min read
One Time Password (OTP) algorithm in Cryptography
Authentication, the process of identifying and validating an individual is the rudimentary step before granting access to any protected service (such as a personal account). Authentication has been built into the cyber security standards and offers to prevent unauthorized access to safeguarded resou
7 min read
Data Integrity in Cryptography