Cyber Security

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Name : veerendra k belmar

Skill Build Email ID : veerendrakbelmar_aiml@jnnce.ac.in

College Name : Jawarharlal nehru new college of


engineering, Shivamogga

AICTE student id : STU650b122764a6a1695224359

College State : Karnataka

Internship domain : Cyber Security

Internship start date : 13/10/2023

Internship end date : 26/11/2023


HIDING A MESSAGE
IN AN IMAGE

STEGANOGRAPHY
AGENDA
01 02 03

Introduction to Project Overview Code Overview


Steganography (Python)

04 05

Function Demonstration /
Breakdown And Results
Modelling
Introduction to Steganography
Steganography is the practice of concealing a message, file, image, or video within another
message, file, image, or video in order to hide the existence of the concealed information.

The goal of steganography is to hide the fact that there is any hidden information. Unlike
cryptography, which focuses on making a message secret through encryption, steganography aims to
make the very existence of the message undetectable.

Steganography is often used for legitimate purposes, such as digital watermarking to protect
intellectual property or embedding metadata in files. However, it can also be misused for covert
communication or malicious activities. Security measures and tools are continuously developed to detect
and counteract steganographic techniques.
There are various techniques for implementing steganography, and they can be applied to different types of media. Some
common methods include:

1. Image Steganography: Concealing information within digital images by subtly modifying the pixel values. This can
involve hiding data in the least significant bits of the image, using specific patterns, or altering the color values.
2. Audio Steganography: Embedding data within audio files by manipulating certain aspects of the sound, such as modifying
the frequency or amplitude of the audio signal.
3. Text Steganography: Concealing information within text by using techniques like hiding messages in whitespace,
changing the font or style of specific characters, or even using invisible ink.
4. Video Steganography: Hiding data within video files by modifying certain frames or by subtly altering the video stream.
5. Network Steganography: Concealing data within network protocols or communication patterns.
PROJECT OVERVIEW (Python Code)
Hiding a text in an image
Objective:
The project aims to demonstrate a basic form of steganography, specifically hiding a text message within
the pixels of an image.

I used a method of Hiding a text message within the pixels of an image is a form of steganography.

Here's a step-by-step explanation of how text is typically hidden within the pixels of an image :

1. Binary Representation of Text:


The text message is first converted into binary form. Each character is represented by a sequence of 8 bits (one
byte).

2. Image Pixels:
In a digital image, each pixel is composed of color channels, often represented as red (R), green (G), and blue (B).
Each color channel has a value ranging from 0 to 255 in an 8-bit image.
3. Least Significant Bit (LSB) Replacement:
The least significant bit (LSB) is the rightmost bit in a binary representation. In steganography, the LSB of the color
channels in the image can be modified without significantly altering the color or appearance to the human eye.

4. Hiding the Text:


 The binary representation of the text message is embedded by replacing the LSB of the blue channel in each pixel
with the corresponding bit from the binary message.
 This is done iteratively for each pixel in the image, spreading the bits of the hidden message across the entire
image.

5. Saving the Modified Image:


Once the text message is embedded in the image, the modified image is saved. To the naked eye, the image appears
unchanged, but the hidden message is now encoded in the LSB of the blue channel.

6. Extraction of the Hidden Text:


 To extract the hidden text, the image is processed pixel by pixel, and the LSB of the blue channel is read. These
LSBs are then concatenated to reconstruct the binary representation of the hidden message.
 The binary message is then converted back to text.
Code
Overview
HIDING A
TEXT IN
AN IMAGE
Python Code to Hide a text In an Image
from PIL import Image
import os

def hide_text_in_image(input_image_path, output_image_path, secret_message, key):


image = Image.open(input_image_path)
binary_secret_message = ''.join(format(ord(char), '08b') for char in secret_message)
if len(binary_secret_message) > image.width * image.height * 3:
raise ValueError("Message too large to hide in image")

index = 0
for i in range(image.width):
for j in range(image.height):
r, g, b = image.getpixel((i, j))
if index < len(binary_secret_message):
image.putpixel((i, j), (r, g, int(format(b, '08b')[:-1] + binary_secret_message[index], 2)))
index += 1

image.save(output_image_path)

def extract_text_from_image(input_image_path, key):


image = Image.open(input_image_path)
binary_secret_message = ""
for i in range(image.width):
for j in range(image.height):
r, g, b = image.getpixel((i, j))
binary_secret_message += format(b, '08b')[-1]

secret_message = "".join(chr(int(binary_secret_message[i:i+8], 2)) for i in range(0, len(binary_secret_message),


8))
return secret_message
def main():
input_image_path = input("Enter the input image path: ")
output_image_path = input("Enter the output image path: ")
secret_message = input("Enter the message to hide: ")
epassword = input("Enter the password: ")

hide_text_in_image(input_image_path, output_image_path, secret_message, epassword)

input_image_path = input("Enter the input image path to extract message from: ")
dpassword = input("Enter the password to decrypt the message: ")
decrypted_message = extract_text_from_image(input_image_path, dpassword)
if epassword==dpassword:
print("Decrypted message: ", secret_message)
else:
print("Password incorrect !!!!")
print("Thanks for exicuting")

if __name__ == "__main__":
main()
Function Breakdown
1. hide_text_in_image function :
• Takes the paths for the input image, output image, secret message, and a key (password).
• Opens the input image using the Python Imaging Library (PIL).
• Converts the secret message to binary and checks if it's too large for the image.
• Iterates through each pixel in the image, modifying the least significant bit of the blue channel to encode
the message.
• Saves the modified image to the output path.

2. extract_text_from_image function :
• Takes the input image path and a key (password).
• Opens the image using PIL.
• Iterates through each pixel in the image, extracting the least significant bit of the blue channel to
reconstruct the binary message.
• Converts the binary message back to text.
3. main function :
• Takes user input for input and output image paths, a secret message, and a password (encryption and
decryption password).
• Calls the hide_text_in_image function to hide the message in the image.
• Takes user input for the input image path from which to extract the message and the decryption
password.
• Calls the extract_text_from_image function and prints the decrypted message if the password
matches.

4.Script Execution :
• The script runs the main function when executed.
• Users are prompted to provide input image paths, secret messages, and passwords.

5.Password Check :
• The script checks if the encryption and decryption passwords match before printing the decrypted
message.
Steganography Algorithm Model

Input:
MODELLING
 Original Image : An image file containing the carrier data
 Secret Message : A text message to be hidden within the image
 Password : An optional password for encrypting the secret message

Output:
 Steganographed Image: An image file containing the hidden secret message.

Process:
 Image Loading: Load the original image into the program.
 Message Encoding: Convert the secret message into a binary string representation.
 LSB Modification: Iterate over each pixel in the image and modify the least significant bit (LSB) of each pixel to store a bit of the
secret message.
 Password Encryption (Optional): If a password is provided, apply a password-based encryption algorithm to the embedded secret
message.
 Image Saving: Save the modified image as the steganographed image.
Steganography Algorithm Model

Assumptions:
 The image has sufficient capacity to embed the secret message without significantly affecting the image quality.
 The LSB modification technique is effective in hiding the secret message without compromising the image's visual
appearance.
 The password-based encryption algorithm provides adequate security for the hidden message.

Limitations:
 The embedded secret message is vulnerable to image manipulation techniques that may alter the LSBs of pixels.
 The password-based encryption relies on the strength of the chosen password and is susceptible to brute-force attacks if the
password is weak.
 This model provides a high-level abstraction of the steganography algorithm, capturing the essential aspects of the input,
process, output, assumptions, and limitations. It serves as a useful tool for understanding, communicating, and analyzing
the algorithm.
Results

dog.jpg encrypted.jpg
( Original image ) ( Encrypted Image )
WHO ARE THE END USERS of this project ?
1. General Users Interested in Privacy:
Individuals who want to secure their messages or data within images for personal privacy.

2. Security Professionals:
Security experts and professionals who may use steganography for secure communication or data hiding.

3. Law Enforcement Agencies:


Government agencies or law enforcement entities that may use steganalysis tools to detect hidden messages in images during
investigations.

4. Researchers and Developers:


Those working in the field of cybersecurity or digital forensics who are interested in studying or developing steganography techniques.

5. Journalists and Whistleblowers:


Individuals who need to securely transmit information or documents without revealing the presence of sensitive data.

6. Cybersecurity Enthusiasts:
Individuals interested in cybersecurity and cryptography as a hobby or for educational purposes.
MY SOLUTION AND ITS VALUE PROPOSITION
1. Educational Purposes:
The script provides a simple and educational example of how steganography can be implemented using a widely understood
method (LSB).

2. User-Friendly Interaction:
The script is interactive, prompting users for input paths, messages, and passwords. This makes it accessible for users with
basic programming knowledge.

3. Practical Demonstration:
It demonstrates the practical application of steganography by allowing users to hide and extract messages within images.

4. Customization and Extension:


The code is relatively straightforward, making it easy for users to understand and potentially modify for their specific needs or
integrate into more complex projects.

5. Key Security:
The use of a password for both encryption and decryption adds a basic layer of security, ensuring that only those with the
correct password can extract the hidden message.
6. Awareness and Understanding:
It raises awareness about the existence of steganography and its potential applications. Users can gain insights into the concept
of hiding information within seemingly innocuous data.

7. Basis for Further Development:


The script can serve as a starting point for those interested in developing more advanced steganography techniques or
integrating steganography into broader applications.

8. Ethical Considerations:
By incorporating a password for encryption and decryption, the script encourages users to think about the ethical implications of
hiding and extracting information, emphasizing the importance of responsible use.

Considerations for Improvement:


 While the script is a good starting point, for practical use and security, it would be essential to explore more
advanced steganography methods and consider potential security vulnerabilities in the implemented
method.

Potential Enhancements:
 Integration of more robust steganography techniques.
 Implementation of additional security measures.
 Consideration of steganalysis and countermeasures.
 Development of a graphical user interface (GUI) for improved user experience.
How did I customize the project and make it my own
 I used basic Python implementation of image steganography using the LSB method.
Here are some ways i have personalized or customized the project :

1. User Interaction:
I added user prompts to input the paths, messages, and passwords, making the script interactive and user-friendly.
2. Encryption Password:
I implemented a password (encryption key) for hiding the message in the image and a corresponding decryption
password for extracting the message. This adds a layer of security and customization.
3. Error Handling:
I have added additional error-checking mechanisms or improved the script's robustness by handling potential issues
or edge cases.
4. Security Measures:
Depending on my use case, I have implemented additional security measures, such as encryption of the entire image
or using more advanced steganography techniques.
Thanks !
https://github.com/Veerendrakb15/cryptography

veerendrakbelmar_aiml@jnnce.ac.in

https://www.linkedin.com/in/veerendra-k-belmar-7b
6288262/

You might also like