Homework 2 CSCI 1112

$35.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

2 Steganography

Steganography is the practice of encoding messages into and decoding messages from images. Steganography is a
unique form of encryption because it is difficult to detect that a message has been encrypted into the image medium,
so it can be used to encrypt in plain sight. The success of this practice is dependent on making minor changes that are
difficult to detect so that these changes are indistinguishable from noise. For this exercise, we will use a very simple
approach that could easily be improved for wider application.

Your implementation will copy the original key image into a new cypher image and will make subtle changes to the
pixel values in the cypher image using a sparse pattern. Each pixel that you modify will be changed by an amount
based on a the position of a letter in the alphabet. In order to spread out the error that we are introducing into the
cypher image, your implementation must change every tenth pixel in every tenth row beginning with the first
row and first column.

A framework for this program has been provided in Steganography.java and a set of unit tests have been
provided in StegUnitTest.java. In order to compile and test your work, compile StegUnitTest.java and
run StegUnitTest.

2.1 Base

The requirements in this section constitute a 90% solution. You must implement the following functions using the
following function signatures:
public static int[][][] copy(int[][][] px)
public static int[] colorError( int[] keyPixel, int[] cypherPixel )
public static int[] positionToError( int chpos )
public static int errorToPosition( int[] error )
public static int[][][] encrypt(String s, int[][][] pxKey)
public static String decrypt(int[][][] pxCypher, int[][][] pxKey)

2.1.1 Base Functions

This section gives a general explanation of the requirements for each function. More information may be available in
the function headers and in how the functions are unit tested.

2
int[][][] copy(int[][][] px)
copy performs a deep copy of the array of pixels px to another array and returns the deep copy.
int[] colorError( int[] keyPixel, int[] cypherPixel )
colorError computes the error in the color channels between two ARGB pixels. The array that is returned consists
only of the error in the RGB channels.

int[] positionToError( int chpos )
positionToError computes the RGB color error from the position of a character in the alphabet. This function
maps a character representation to color information. In the base requirements, the color error is uniform across all
channels, so the same error is stored in every RBG channel. For example:
• ’A’ is the first letter in the alphabet and in a zero based system it would be in position 0, so the RGB error would
be [1,1,1].

• ’Z’ is the last letter in the alphabet and in a zero based system it would be in position 25, so the RGB error
would be [26,26,26].
int errorToPosition( int[] error )
errorToPosition computes the position of a character in the alphabet from the RGB color error. This function
maps a color back to a character representation. By knowing the position of a character in the alphabet, we can then
compute the ASCII representation of the character. In the base requirements, the color error is uniform across all
channels, so the same error is stored in every RGB channel. For example:
• An RGB error of [1,1,1] indicates that the character encoded is the first character in the alphabet and in a zero
based system this would translate to the value 0.

• An RGB error of [26,26,26] indicates that the character encoded is the last character in the alphabet and in a
zero based system this would translate to the value 25.

int[][][] encrypt(String s, int[][][] pxKey)
encrypt takes a string consisting of only alphas (no numbers or non-alphabet characters), encodes the letters
into a copy of the key image, and returns the newly encoded image. encrypt must use the functions copy and
positionToError. encrypt only subtracts the error from the color channels in a pixel which is acceptable only
because this is tested against a full color (white) image.

String decrypt(int[][][] pxCypher, int[][][] pxKey)
decrypt takes two images, a cypher containing an encoded message and a key image representing the original
image that the message was encoded into, and returns a string consisting of only alphas (no numbers or non-alphabet
characters). decrypt must use the functions colorError and errorToPosition.

2.2 Extension

The requirements in this section represents the remaining 10% of your potential grade. You will receive no credit
for the extension if your base implementation is incorrect. Focus first on getting the base program fully correct,
then consider the extension requirements. You must implement the following functions using the following function
signatures:
public static int[] positionToError2( int chpos )
public static int errorToPosition2( int[] error )
public static int[][][] encrypt2(String s, int[][][] pxKey)
public static String decrypt2(int[][][] pxCypher, int[][][] pxKey)

2.2.1 Extension Functions

int[] positionToError2( int chpos )
positionToError2 computes the RGB color error from the position of a character in the alphabet. This function
maps a character representation to a color. In the extension requirements, the color error is spread across all channels,
so only part of the overall error is stored in an individual color channel and the sum of the error across all channels
encodes the character. For example:
• ’A’ is the first letter in the alphabet and in a zero based system it would be in position 0, so the RGB error would
be [1,0,0].

• ’B’ is the second letter in the alphabet and in a zero based system it would be in position 1, so the RGB error
would be [1,1,0].
• ’Z’ is the last letter in the alphabet and in a zero based system it would be in position 25, so the RGB error
would be [9,9,8].
This approach reduces the overall change in color for a pixel, so the changes are less obvious and a large range of
values can be encoded into a pixel.

int errorToPosition2( int[] error )
errorToPosition2 computes the position of a character in the alphabet from the RGB color error. This function
maps a color back to a character representation. By knowing the position of a character in the alphabet, we can then
compute the ASCII representation of the character. In the extension requirements, the color error is spread across all
color channels, so only part of the error is stored in a single RGB channel. For example:
• An RGB error of [1,0,0] indicates that the character encoded is the first character in the alphabet and in a zero
based system this would translate to the value 0.

• An RGB error of [1,1,0] indicates that the character encoded is the second character in the alphabet and in a
zero based system this would translate to the value 1.
• An RGB error of [9,9,8] indicates that the character encoded is the 26th character in the alphabet and in a zero
based system this would translate to the value 25.

int[][][] encrypt2(String s, int[][][] pxKey)
4
encrypt2 takes a string consisting of only alphas (no numbers or non-alphabet characters), encodes the letters
into a copy of the key image, and returns the newly encoded image. encrypt must use the functions copy and
positionToError2. encrypt2 will be compared against a gradient where some channels are no color and some
channels are full color. When encoding the error, if the color channel is closer to no color than full color add the error
for that channel otherwise subtract the error for that channel.

String decrypt2(int[][][] pxCypher, int[][][] pxKey)
decrypt2 takes two images, a cypher containing an encoded message and a key image representing the original
image that the message was encoded into, and returns a string consisting of only alphas (no numbers or non-alphabet
characters). decrypt must use the functions colorError and errorToPosition2.
5