Question: In your third project, you will be writing a pair of steganography programs that will hide and extract data from images. There are two parts
In your third project, you will be writing a pair of steganography programs that will hide and extract data from images. There are two parts to this project: First Part In the first part, you will write a program (Stego) that will hide a binary file in a PGM formatted image. PGM files are grayscale images that encode each pixel as an 8-bit value, ranging between 0 (0x00) and 255 (0xFF). The value 0x00 represents a black pixel and 0xFF is a white pixel. The trick to hiding data inside of a picture is to change the least significant bit (LSB) of each pixels byte. For example, if the original pixel has the value of 0xAE (10101110), we can encode a one in the LSB to turn it into 0xAF (10101111). The difference in color and brightness between a pixel with the value 0xAE and 0xAF is so tiny that a human would not see any difference! Steganography is hiding data in a way that you cant even tell anything is hidden in there. In this first part of the project, you will be hiding a binary data file in the least significant bit of each byte of the PGM image. The binary file you are hiding is known as the payload, the original image is the cover, and the modified PGM image that contains your payload is called the stego image. Second Part In the second part of your project, you will write a program StegoExtract that will take the stego image generated from the program you wrote for part one and extract the payload from it. Once the binary file is recovered, it will be identical to the original payload file. Since we are working with binary data files for the payload, the type can be any file that will fit. As long as it is small enough, you can encode other images into this image, in addition to encoding text files. 2.1 Starting Files For this project, we are providing five files that will be used as the starting point for this project: image.c This provides all of the functions to read and write to PGM images. image.h Header for image.c with all of the macros and prototypes you need. Stego.c // Starter File for Part One StegoExtract.c // Starter File for Part Two http://cs.gmu.edu/~zduric/cs262/Homeworks/half.pgm cs262.pgm image.c Contains several functions for reading and writing PGM and PPM images and binary files. Several macros, and examples of their use, have also been provided in this file to simplify image byte manipulation. GetGray(i) This macro will get and return byte i from the source image as an unsigned char. SetGray(i,g) This macro will set byte i in the destination image with the unsigned char g. GetByte(i) This macro will get and return byte i from the input binary data file. SetByte(i,val) This macro will set byte i in the output binary file to unsigned char val. Look at the definition of the macros provided in image.h to see how they affect the files in Stego.c Stego.c Starting point for Part One of your project. This will be the main source file for your program to embed a binary data file within a PGM image. Comments have been added to direct your solution. 2.2 Stego.c Design There are three parts to embedding data within the cover image. 1. You will use the first 32-bytes of the cover image to embed the 32-bits of b.size (the size field for the binary data file (payload)). You have access to this in Stego.c. Hint: GetGray(0); will get the first byte of the cover image and SetGray(0, b0); will replace it with b0 2. The second 32-bytes of the cover image will be used to embed the 8 digits of your G# in numerical form (using 4-bits per digit). 3. After this, you will embed each byte of your data into the LSBs of the cover image. This means you will be using 8 bytes of the image to hold each 1 byte of your information. This will use 8 * b.size bytes in total to embed the data (b.data) Hint: GetByte(0) gets the first byte of the payload data file, and SetByte(0, b0) will replace it with b0 Note that you can get and set image bytes and binary data using the provided macros. Unless you get really ambitious and want to play with color images (PPM format images), you only need to use the macros: GetGray, SetGray, and GetByte. The skeleton program (Stego.c) can be used to understand the operation of the macros and functions. You will be adding the main code for you solution to the following areas: // embed four size bytes for the Buffer s size field Write your code here to embed the b. size field . . . // embed the eight digits of your G# using 4 bits per digit Write your code here to embed your G# with the given format . . . // here you embed information into the image one byte at the time // note that you should change only the least significant bits of the image Write your code here to use your getlsbs or setlsbs functions to perform the ops . 2.3 StegoExtract.c Design For your extraction in Part Two, you will create a new source file, StegoExtract.c, that will use the same general techniques as Stego.c, but will undo the operations you performed in Part One. Basically, this will extract the LSBs from the first 32-bytes to form a 32-bit integer (b.size). You will then need to malloc memory for this many bytes and assign that pointer to b.data. This will hold your extracted payload. You will then extract the LSBs from the next 32-bytes to extract your G-Number. After this, you will extract the LSBs each subsequent 8-bytes to form each 1-byte of your data, b.data. At the end, you will need to make a call to WriteBinaryFile(argv[2],b); to output b as the extracted payload data to your user input output filename. Unless you get really ambitious and want to play with color images (PPM format images), you only need to use the macros: GetGray and SetByte. 2.4 Compiling To compile the programs, you will use a Makefile. The compiling process will create static objects that you can compile into each of your two programs. The following command references will help you build your makefile. Compile the image code into an object (image.o) This will be used by Parts One and Two gcc -c image.c Compile your Part One file into an object (Stego.o) gcc -c Stego.c Compile your Part Two file into an object (Extract.o) gcc -c Extract.c Compile and Link to Create your Stego Executable gcc -o Stego Stego.o image.o Compile and Link to Create your StegoExtract Executable gcc -o StegoExtract StegoExtract.o image.o 2.5 Executing Stego Stego requires 3 parameters when run: a PGM image filename, the name of an output PGM file (the stego image), and the name of the payload file. StegoExtract StegoExtract will requires 2 parameters when run: a PGM (the stego image) filename and the name of the payload file to output
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
