logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

you will demonstrate your ability with the C programming language

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

In this coursework, you will demonstrate your ability with the C programming language and its standard library by writing a steganography program which encodes and decodes secret messages in bitmap images.

This coursework contributes to the following learning outcomes of the course:

Ability to develop efficient, resource-conscious code.

Practical skills in low-level, systems programming, with effective resource management.

Ability to articulate system-level operations and to identify performance implications of given systems.

This is an individual assessment. The code and documentation you submit must be entirely your own work.

If you have any questions, please ask me <a.sampson@hw.ac.uk>.

The problem

This coursework involves writing a simple steganography program in C, called steg. steg can operate in two modes — encode and decode — selected by the first command-line argument being e or d.

An RGB colour bitmap image consists of a grid of pixels, each of which has red, green and blue colour values. To encode text inside an image, your program will replace the red value in successive random pixels in the image with characters from the text, outputting a new image.

When encoding, your program will be invoked as:

./steg e old.ppm >new.ppm

It must prompt for a message to encode, and output the new image to stdout (in this case we have redirected it to a file).

To decode the text, your program will compare the new image with the old image, and extract characters from the new one where it differs from the old one.

When decoding, your program will be invoked as:

./steg d old.ppm new.ppm

It must decode the message and output the hidden text to stdout.

The PPM image format

You will work with Plain PPM format images. This is one of a family of simple open source image formats, designed to be read and written easily by C programs. See the PPM specification for full details of PPM and Plain PPM.

A Plain PPM file consists of ASCII text:

P3

# comment1

# ...

# commentN

width height

max

r1 g1 b1

r2 g2 b2

r3 g3 b3

...

where:

P3 - code indicating Plain PPM format

comment - arbitrary optional comment text

width - integer number of columns

height - integer number of rows

max - integer maximum colour value - usually 255

ri gi bi - integers between 0 and max for pixel i's red, green and blue values

All integers are in decimal.

(From now on, I will refer to Plain PPM just as PPM.)

Getting started

You will need a Linux C development environment, like we have been using in the practical exercises. This might be:

a MACS lab machine

a MACS machine remotely, using x2go

the MACS Linux Virtual Machine on your own computer

a regular Linux installation on your own computer

You may like to refer to Hans-Wolfgang Loidl's Linux Introduction.

Cloning the project

You are provided with a template project containing an outline source file. You must use Git and the MACS GitLab Student server to download the template project and to submit the assessment.

First, fork this project.

Then clone your fork on your Linux system, e.g. (replacing username with your username):

git clone git@gitlab-student.macs.hw.ac.uk:username/f28hs-2021-22-cwk1-c.git

Make sure that you can compile the starter code before you start making changes to the steg.c file. Change into the project directory, and run:

make

(This may print some warnings because the code is incomplete.)

As you progress through the coursework requirements, push your work to GitLab. Remember to create small incremental improvements with Git commits — you may like to refer to Rob Stewart's Introduction to Git video for the lifecycle of files in a Git repository. When you push your commits, GitLab will check that your file can be compiled.

Test dataset

A collection of PPM image files for you to test your steganography program with is available from Canvas, under Course Information > Assessment.

You may notice some PPM files in this collection have a new line after every colour value, whilst others have the R, G and B values for a pixel on one row. Either is fine — the PPM specification allows any kind of whitespace between numbers.

Requirements

This project as a whole is marked out of 20 points, and makes up 50% of your final mark for the course.

The program overall should be valid C99 (or later), and should be robust against error.

Work through the steps below in order.

1 - (2 points) Storing PPM images

In steg.c, complete the declaration of struct PPM, which holds the image read from a PPM file.

This will need to include the information from the PPM header (width, height, max), and a pointer to a dynamically-allocated array containing the pixel data. Your program should be able to deal with PPM files with arbitrary numbers of rows and columns.

2 - PPM functions

Implement in steg.c the following functions.

You may also write additional helper functions or type declarations if you like. The template includes some already, e.g. struct Pixel and readPPM, but you can rename or remove these provided you implement struct PPM, getPPM, showPPM, encode and decode.

2a - (2 points) Reading PPM files

struct PPM *getPPM(FILE *f);

to return a new struct PPM, containing the PPM image read from open file f.

Use the fscanf function to read numbers from the file. Once you know width and height, construct a dynamic array of the appropriate size. Don't worry about handling comments in the PPM file for now.

2b - (2 points) Writing PPM files

void showPPM(const struct PPM *img);

to output the PPM image img to stdout (e.g. by using printf), following the syntax in the PPM specification.

You should test this function by using it to write out an image loaded with getPPM. The template code's main function has an extra t mode for this.

2c - (2 points) Encode data

struct PPM *encode(const char *text, const struct PPM *img);

to return a copy of PPM image img with message text hidden in its red pixel values.

You will need to make it replace successive random red pixels with the characters from the message. How you select pixels is up to you, but make sure that the pixels are chosen in a consistent order (e.g. left to right, top to bottom) and enough pixels are selected to encode all of the message.

2d - (2 points) Decode data

char *decode(const struct PPM *oldimg, const struct PPM *newimg);

to return a new string containing the message hidden in the red pixel values of PPM image newimg, by comparing it with the red pixel values of PPM image oldimg.

The length of the string that it allocates and returns will depend on the length of the message. You may impose a limit on the maximum length of a decoded message if this makes the implementation easier.

3 - (6 points) Steganography program

Complete the main behaviour of the steg program, which encodes or decodes images based on its command-line arguments as described above.

4 - (2 points) Additional PPM features

For an additional 2 points, implement one of the following two features:

Make getPPM and showPPM read and write comments, by storing the comments as a linked list of strings in struct PPM. You can assume that any comment lines will always be immediately before width (although the PPM specification says they're allowed to occur anywhere in the file). You will need to rework how you read width — if the first character you read is a #, then you have a comment, else it must be a digit and should be counted as part of width.

Make getPPM handle normal PPM files as well as Plain PPM. Normal PPM files start with P6 instead of P3, and have the image data stored directly as bytes (one or two bytes per colour, depending on max) rather than as decimal numbers — see the PPM specification for more details. You can read data like this using the fread function.

5 - (2 points) Report

In Report.md, you should give a brief description — no more than a couple of pages of text — of:

your program design

your choice of data structures and algorithms

Write Report.md using Markdown syntax, which will allow GitLab to render it nicely as HTML. See the Markdown Guide, or the help within GitLab, for more details.

 

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

674 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

523 Answers

Hire Me
expert
Husnain SaeedComputer science

930 Answers

Hire Me
expert
Atharva PatilComputer science

515 Answers

Hire Me
June
January
February
March
April
May
June
July
August
September
October
November
December
2025
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30