0% found this document useful (0 votes)
173 views5 pages

Lab 1 - Stegnography

Uploaded by

Pranav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views5 pages

Lab 1 - Stegnography

Uploaded by

Pranav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab 1 Steganography Lab

In this lab, students will understand.


• Classical Steganography.
• Text Steganography.
• Image Steganography.
• Audio Steganography.
• Video Steganography.

Table of Contents
Overview......................................................................................................................................2
Task 1: Simple Classical Steganography Tools..............................................................................2
Task 1a: Analyse the hidden message....................................................................................................2
Task 2: Text Steganography.........................................................................................................2
Task 2a: Adding text files inside an Image using the copy command..................................................2
Task 3: Images Steganography.....................................................................................................2
Task 3a: LSB Steganography..................................................................................................................2
Task 3b: Image header..........................................................................................................................2
Task 4: Audio Steganography.......................................................................................................2

Overview
Objective of this lab is to make students get familiarise with steganographic tools.

1. Classical steganographic methods.


2. Create a digital document with a hidden message.
3. Hiding images in an image.
4. Hiding text in an audio file.
Lab Tasks
Task 1: Simple classical steganography tools
Task 1a: Analyse the hidden message.

Figure 1: Invisible man

Task 2: Text Steganography


Task 2a: Adding text files inside an Image using the copy command.
Step 1: Create 2 text files text1.txt and text2.txt.
Step 2: Add text1.txt and text2.txt to text.zip/ text.rar.
Step 3: Copy the contents of text.rar to the steganographic image using the following
command

$copy /B stegno.jpg + text.rar new.jpg.

Task 3: Images Steganography


Task 3a: LSB Steganography

Python Program for LSB steganography


import numpy as np from PIL
import Image

def Encode(src, message, dest):

img = Image.open(src, 'r') width,


height = img.size
array = np.array(list(img.getdata()))

if img.mode == 'RGB': n = 3
elif img.mode == 'RGBA':
n=4 total_pixels = array.size//n

message += "$t3g0"
b_message = ''.join([format(ord(i), "08b") for i in message])
req_pixels = len(b_message)

if req_pixels > total_pixels: print("ERROR: Need larger file


size")

else:
index=0
for p in range(total_pixels): for q in
range(0, 3):
if index < req_pixels:
array[p][q] = int(bin(array[p][q])[2:9] +
b_message[index], 2)
index += 1

array=array.reshape(height, width, n)
enc_img = Image.fromarray(array.astype('uint8'), img.mode)
enc_img.save(dest)
print("Image Encoded Successfully")

Step 3: Make the Decoder Function

Firstly, we repeat a similar procedure of saving the pixels of the


source image as an array, figuring out the mode, and calculating the
total pixels.
def Decode(src):

img = Image.open(src, 'r')


array = np.array(list(img.getdata()))
if img.mode ==
'RGB': n = 3
elif img.mode ==
'RGBA': n = 4

total_pixels = array.size//n

def Decode(src):

img = Image.open(src, 'r')


array = np.array(list(img.getdata()))

if img.mode ==
'RGB': n = 3
elif img.mode == 'RGBA':
n = 4 total_pixels = array.size//n

hidden_bits = ""
for p in
range(total_pixels): for
q in range(0, 3):
hidden_bits += (bin(array[p][q])[2:][-1])

hidden_bits = [hidden_bits[i:i+8] for i in


range(0, len(hidden_bits), 8)]

message = ""
for i in
range(len(hidden_bits)): if
message[-5:] == "$t3g0":
break
else:
message += chr(int(hidden_bits[i],
2)) if "$t3g0" in message:
print("Hidden Message:", message[:-

def Stego():
print("--Welcome to $t3g0--") print("1:
Encode") print("2: Decode")

func = input()

if func == '1':
print("Enter Source Image Path")
Cryptography
Lab 1: Steganography Lab

src = input()
print("Enter Message to Hide") message = input()
print("Enter Destination Image Path") dest = input()
print("Encoding...") Encode(src, message,
dest)

elif func == '2':


print("Enter Source Image Path") src = input()
print("Decoding...") Decode(src)

else:
print("ERROR: Invalid option chosen") Stego()

Task 3b: Image header


The Lab1_Task 3b_challenge.jpg file contains some useful information. But
the file seems to be corrupted, help me fix it and find the Information!

Hint:
 Have you ever used Hex editors?
 Find the header information of the given image file format (example JPEG).
 Check the header info of given file and if info is wrong correct it and reopen.
 Online hex editor link: https://hexed.it/
 Replace starting hex digits with FF D8 FF E0
Task 4: Audio Steganography
The audio file Lab_1_Task4.wav file has some information in it. Can you find the information
hidden in the audio file?

Hint:
 Have you tried to view an audio file in Sonic Visualiser?
 Add spectrogram layer after opening the audio file in sonic visualiser.
How to create Audio Steganography?

 First create a BMP file with text.


 Open the bitmap file in CoagulaLight1666 application.
 Click on render image without blue/ noise.
 Save the file using save sound as option.

5
BNM Institute of Technology Department of CSE

You might also like