0% found this document useful (0 votes)
7 views

CYB322 Course Project 101

Uploaded by

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

CYB322 Course Project 101

Uploaded by

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

University of Hafr AlBatin

College of Computer Science and Engineering

CYB322 COURSE PROJECT REPORT


Secure Data Transfer Over Internet Using Image
Steganography
First Semester, 2024 / 2025

Project Team Members


Student ID Name Email address Role
Nura Abdulsalam
1 2211007227 [email protected] Leader
Alshammari
Raghad Saeed
2 2211005152 [email protected] Member
Alzahrani
Rasil Abdullah
3 2201002658 [email protected] Member
Alanazi

Instructure: Dr. SELMA EINASIR ABDELLA


Contents
SECTION 1: INTRODUCTION .......................................................................................................................... 3
1.1 Introduction to Steganography: ...................................................................................................... 3
1.2 Cryptography and Steganography:.................................................................................................. 3
1.3 Steganography Methods and Algorithms: ...................................................................................... 4
1.4 The Importance of Steganography: ................................................................................................. 6
SECTION 2: STEGANOGRAPHY IN THEORY.................................................................................................... 7
SECTION 3: IMPLEMENTATION ................................................................................................................... 10
SECTION 4: EXPERIMENTAL RESULTS ......................................................................................................... 15
SECTION 5: EXPLANATION AND DISCUSSION OF THE RESULTS .................................................................. 16
SECTION 6: CONCLUSION ............................................................................................................................ 17
SECTION 1: INTRODUCTION

1.1 Introduction to Steganography:

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.

1.2 Cryptography and Steganography:

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 to 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.

3
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.

1.3 Steganography Methods and Algorithms:

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.

4
Figure1: Process of Image Steganography

In steganography, what algorithm is used?

His steganography approach entails concealing a huge amount of data (picture, audio,

and text) within a color 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.

5
I. Run the following command to install the ‘PIL' library:

pip install pillow

II. Or in CMD type the same command for instant installation.

2) Import the required libraries.

3) Define the functions for hiding and extracting secret data.

4) Hide secret text in an image.

5) Extract the secret text from the image.

1.4 The Importance of Steganography:

Storing and communicating secret and/or private information has become part of our

daily life whether it is for our employment or personal well-being. Therefore, secure

storage and transmission of the secret information have received the undivided

attention to many.

Is steganography a secure method of communication?

When steganography is employed alone, it is secure 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.

6
SECTION 2: STEGANOGRAPHY IN THEORY

In theory Image method is the practice of hiding information by using the cover item as the

image. Images are a popular cover source in digital steganography because the digital

representation of a picture contains many bits. There are several methods for concealing

information within a picture. Typical techniques including:

• Least Significant Bit Insertion

• Masking and Filtering

• Redundant Pattern Encoding

• Encrypt and Scatter

• Coding and Cosine Transformation

Least Significant Bit (LSB) is one of the most popular techniques used.

To understand how LSB works, first we need to know how a pixel works.

1- A pixel color is defined by 3 channels: Red, Green, Blue, also known as RGB.

Each channel can have a value in a range between 0 and 255. The higher the value of a channel,

the more intense its color.

You can use any combination of those channels to generate the color you want.

Binary. Each channel of a pixel needs 1 byte, which means, 8 bits, that is, 8 1s and 0s. For

example, a blue pixel:

7
It will result in a blue pixel, but if we change the value of the blue channel from 255 to 254:

We just change a single bit of the pixel, the last one (the Least Significant Bit).

The two blue colors are similar. Even if they’re joined, we won’t be able to see the difference:

We can make this change on the 3 channels; it means that we can store 3 bits per pixel and the

final image will look much like the original one.

2- ASCII Table

To encode the message, we get the respective decimal value from the ASCII table. If we want to

encode a single letter “a”, the decimal value for this letter according to the table is 97, in

binary: 01100001. How we can store 3 bits per pixel, only changing the last bit, we’ll need 3

pixels to encode the ‘a’ in our image. The first pixel will store 0 1 1, on the last bits of each

RGB channel, the second will store 0 0 0, and the third will store 0 1 (the blue channel will not

be needed for this one). Joining the last bits of these pixels we’ll have: 01100001, converting

this binary to decimal will result in 97, which is “a” according to the ASCII table.

8
Figure2: QR code as an Image.

In this illustration, QR code represents the cover file such as image, and it shows that binary bits

are modified using LSB technique it modifies the last bit of each byte to embed or hide one bit

of the file. If the attacker wants to hide one megabyte of a file using this method, they need an

image of eight megabytes in size. With this technique, it’s difficult to compare the original picture to

the modified one. It also changes the last bit of each of those bytes to hide one bit of data. So, to hide

one megabyte of data using this method, you’ll need an eight-megabyte image file. Since changing the

last bit of the pixel value doesn’t change the picture enough to be seen, a person looking at the original

picture and the modified picture won’t be able to tell the difference.

Figure3: LSB Algorithm.

Our program represents the LSB Algorithm as the appropriate technique to our project.

9
SECTION 3: IMPLEMENTATION

We used python as the programming language for our program.

#import modules
from tkinter import *
import tkinter.filedialog
from tkinter import messagebox
from PIL import ImageTk
from PIL import Image
from io import BytesIO
import os

class IMG_Stegno:
output_image_size = 0

#Main frame
def main(self, root):
root.title('ImageSteganography')
root.geometry('600x700')
root.resizable(width =True, height=True)
root.config(bg = '#f0f0f0')
frame = Frame(root)
frame.grid()

title = Label(frame,text='\n\n\n\nWelcom to\nSecure Data Transfer Over Internet\nUsing Image Steganography


Project\nCYB322 2024\n')
title.config(font=('Times new roman',23, 'bold'))
title.grid(pady=10)
title.config(bg = '#f0f0f0')
title.grid(row=1)
title5 = Label(frame,text='To start please select your choice')
title5.config(font=('Times new roman',12, 'bold'))
title5.grid(pady=10)
title5.config(bg = '#f0f0f0')
title5.grid(row=2)

encrypt = Button(frame,text="ENCRYPT",command= lambda :self.encrypt_frame1(frame), padx=20,bg = '#e3f4f1' )


encrypt.config(font=('Times new roman',14), bg='#ef4026')
encrypt.grid(row=10)
decrypt = Button(frame, text="DECRYPT",command=lambda :self.decrypt_frame1(frame), padx=20,bg = '#e3f4f1')
decrypt.config(font=('Times new roman',14), bg='#15b01a')
decrypt.grid(pady = 12)
decrypt.grid(row=12)

root.grid_rowconfigure(1, weight=1)
root.grid_columnconfigure(0, weight=1)

# back function to loop back to main screen


def back(self,frame):
frame.destroy()
self.main(root)

#frame for encode page


def encrypt_frame1(self,F):
F.destroy()

10
F2 = Frame(root)
label1= Label(F2,text='\n\n\n\n\nSelect any image to type\nan encrypted message\n')
label1.config(font=('Times new roman',23, 'bold'),bg = '#f0f0f0')
label1.grid()

button_bws = Button(F2,text='SELECT',command=lambda : self.encrypt_frame2(F2))


button_bws.config(font=('Times new roman',18), bg='#c0c0c0')
button_bws.grid()
button_back = Button(F2, text='CANCEL', command=lambda : IMG_Stegno.back(self,F2))
button_back.config(font=('Times new roman',12),bg='#ffffff')
button_back.grid(pady=15)
button_back.grid()
F2.grid()

#frame for decode page


def decrypt_frame1(self,F):
F.destroy()
d_f2 = Frame(root)
label1 = Label(d_f2, text='\n\n\n\n\nSelect the Image to decrypt it\n')
label1.config(font=('Times new roman',23,'bold'),bg = '#ffffff')
label1.grid()
label1.config(bg = '#f0f0f0')
button_bws = Button(d_f2, text='SELECT', command=lambda :self.decrypt_frame2(d_f2))
button_bws.config(font=('Times new roman',18), bg='#c0c0c0')
button_bws.grid()
button_back = Button(d_f2, text='CANCEL', command=lambda : IMG_Stegno.back(self,d_f2))
button_back.config(font=('Times new roman',12), bg='#ffffff')
button_back.grid(pady=15)
button_back.grid()
d_f2.grid()

#function to encode image


def encrypt_frame2(self,e_F2):
e_pg= Frame(root)
myfile = tkinter.filedialog.askopenfilename(filetypes = ([('png', '*.png'),('jpeg', '*.jpeg'),('jpg', '*.jpg'),('All Files', '*.*')]))
if not myfile:
messagebox.showerror("ERROR!!","You've selected nothing!")
else:
my_img = Image.open(myfile)
new_image = my_img.resize((500,300))
img = ImageTk.PhotoImage(new_image)
label3= Label(e_pg,text='The Selected Image')
label3.config(font=('Times new roman',14,'bold'))
label3.grid()
board = Label(e_pg, image=img)
board.image = img
self.output_image_size = os.stat(myfile)
self.o_image_w, self.o_image_h = my_img.size
board.grid()
label2 = Label(e_pg, text='Enter the message:')
label2.config(font=('Times new roman',14,'bold'))
label2.grid(pady=15)
text_a = Text(e_pg, width=70, height=6)
text_a.grid()
encrypt_button = Button(e_pg, text='CANCEL', command=lambda : IMG_Stegno.back(self,e_pg))
encrypt_button.config(font=('Times new roman',12), bg='#ffffff')
data = text_a.get("1.0", "end-1c")
button_back = Button(e_pg, text='ENCRYPT', command=lambda :
[self.enc_fun(text_a,my_img),IMG_Stegno.back(self,e_pg)])
button_back.config(font=('Times new roman',14), bg='#ef4026')
button_back.grid(pady=15)
encrypt_button.grid()

11
e_pg.grid(row=1)
e_F2.destroy()

# function to decode image


def decrypt_frame2(self,d_F2):
d_F3 = Frame(root)
myfiles = tkinter.filedialog.askopenfilename(filetypes = ([('png', '*.png'),('jpeg', '*.jpeg'),('jpg', '*.jpg'),('All Files', '*.*')]))
if not myfiles:
messagebox.showerror("OOPS!!","You've selected nothing!")
else:
my_img = Image.open(myfiles, 'r')
my_image = my_img.resize((500, 300))
img = ImageTk.PhotoImage(my_image)
label4= Label(d_F3,text='The Selected Image\n')
label4.config(font=('Times new roman',14,'bold'))
label4.grid()
board = Label(d_F3, image=img)
board.image = img
board.grid()
hidden_data = self.decrypt(my_img)
label2 = Label(d_F3, text='Message Decrypted:\n')
label2.config(font=('Times new roman',14,'bold'))
label2.grid(pady=10)
text_a = Text(d_F3, width=50, height=10)
text_a.insert(INSERT, hidden_data)
text_a.configure(state='disabled')
text_a.grid()
button_back = Button(d_F3, text='CANCEL', command= lambda :self.frame_3(d_F3))
button_back.config(font=('Times new roman',12),bg='#ffffff')
button_back.grid(pady=15)
button_back.grid()
d_F3.grid(row=1)
d_F2.destroy()

#function to decode data


def decrypt(self, image):
image_data = iter(image.getdata())
data = ''

while (True):
pixels = [value for value in image_data.__next__()[:3] +
image_data.__next__()[:3] +
image_data.__next__()[:3]]
binary_str = ''
for i in pixels[:8]:
if i % 2 == 0:
binary_str += '0'
else:
binary_str += '1'

data += chr(int(binary_str, 2))


if pixels[-1] % 2 != 0:
return data

#Function to generate data


def generate_Data(self,data):
new_data = []

12
for i in data:
new_data.append(format(ord(i), '08b'))
return new_data

#Function to modify the pixels of image


def modify_Pix(self,pix, data):
dataList = self.generate_Data(data)
dataLen = len(dataList)
imgData = iter(pix)
for i in range(dataLen):
# Extracting 3 pixels at a time
pix = [value for value in imgData.__next__()[:3] +
imgData.__next__()[:3] +
imgData.__next__()[:3]]

for j in range(0, 8):


if (dataList[i][j] == '0') and (pix[j] % 2 != 0):
if (pix[j] % 2 != 0):
pix[j] -= 1

elif (dataList[i][j] == '1') and (pix[j] % 2 == 0):


pix[j] -= 1

if (i == dataLen - 1):
if (pix[-1] % 2 == 0):
pix[-1] -= 1
else:
if (pix[-1] % 2 != 0):
pix[-1] -= 1

pix = tuple(pix)
yield pix[0:3]
yield pix[3:6]
yield pix[6:9]

#Function to enter the data pixels in image


def encrypt_enc(self,newImg, data):
w = newImg.size[0]
(x, y) = (0, 0)

for pixel in self.modify_Pix(newImg.getdata(), data):

# Putting modified pixels in the new image


newImg.putpixel((x, y), pixel)
if (x == w - 1):
x=0
y += 1
else:
x += 1

#Function to enter hidden text


def enc_fun(self,text_a,myImg):
data = text_a.get("1.0", "end-1c")
if (len(data) == 0):
messagebox.showinfo("ALERT!","Please type in ypur message in the TextBox")
else:
newImg = myImg.copy()
self.encrypt_enc(newImg, data)
my_file = BytesIO()
temp=os.path.splitext(os.path.basename(myImg.filename))[0]

13
newImg.save(tkinter.filedialog.asksaveasfilename(initialfile=temp,filetypes = ([('png',
'*.png')]),defaultextension=".png"))
self.d_image_size = my_file.tell()
self.d_image_w,self.d_image_h = newImg.size
messagebox.showinfo("SUCCESS!!!","MESSAGE ENCRYPTED SUCCESSFULLY\n")

def frame_3(self,frame):
frame.destroy()
self.main(root)

#GUI loop
root = Tk()
o = IMG_Stegno()
o.main(root)
root.mainloop()

First, we called all the important modules from the library to implement all used functions in the
program. Then we set up a main frame by defining (main) function with objects including
frames, encryption, and decryption.
We then defined encryption as the encryption method to encrypt the texts into the images. And
the decryption method to decrypt the texts out of the images.
We also made a Function to modify the pixels of an image.

The output of the program is that you have the choice to either encrypt or decrypt any image you
want:
Encryption:
1. Choose any image you want in any type.
2. Type any text you want to encrypt.
3. Click on the encrypt button.
4. Rename the image to differentiate
5. Send the picture to the desired person.
Decryption:
1. Click on the renamed image.
2. Click on the decrypt button.
3. The text will appear below the image.
4. Click on the cancel button to head back to the main frame.

14
SECTION 4: EXPERIMENTAL RESULTS

The pictures below illustrate our program output:

Figure4: Program Output.

15
SECTION 5: EXPLANATION AND DISCUSSION OF THE RESULTS

Program Performance:

• The program performed very well during execution due to the encryption method used
and the programmed functions.

Program Strength:

• The strength point is the LSB Method, it was a great choice to illustrate how a text can be
emerged into an image to look like nothing happened.

Program Difficulties:

• The difficulties were when we tried to configure pixels of images and blend the text
inside, we then settled on extracting 3 pixels at a time to ease the way.

16
SECTION 6: CONCLUSION

In conclusion, image steganography is a vital tool for ensuring data privacy and security in
today's digital world. This comprehensive guide has provided insights into the different types
and techniques of this practice, ranging from spatial to compressed domain steganography.
The LSB technique, PVD technique, spread spectrum technique, and randomized embedding
technique were also explored in-depth. Steganography will continue to be essential in protecting
sensitive information from hackers as technology develops at an unparalleled rate.
It is observed that through LSB Substitution Steganographic method, the results obtained in data
hiding are pretty impressive as it utilizes the simple fact that any image could be broken up to
individual bit-planes each consisting of different levels of information. It is to be noted that as
discussed earlier, this method is only effective for bitmap images as these involve lossless
compression techniques.

17

You might also like