logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

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

expert
Cheryl ZhaoEducation
(4/5)

569 Answers

Hire Me
expert
Christopher OchiengComputer science
(/5)

776 Answers

Hire Me
expert
Alfred DoddData mining
(5/5)

873 Answers

Hire Me
expert
Anuj MittalMathematics
(/5)

784 Answers

Hire Me
Others
(5/5)

Creating the secret message relies on some facts about the way that characters are represented in the computer

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

At a high-level, the aim of this coursework is for you to demonstrate that you can use text files. You are given some starter code; you do not need to change this code. You are required to complete some of the functions as described in this document.

Starting Your Assignment

You are provided with some starter code and some text files which you must download and save before starting the assignment. Feel free to use CoCalc to develop your code.

Running the stegsnow program

There are two ways to run the program from the terminal depending on whether you want to encode or decode a secret message. The code in main() contains code to handle the options you type on the command line, you are not required to edit the code in main().

Encoding a secret message

Note: for the purposes of this coursework, you will only be required to use secret messages that contain the lower case characters a-z and space, for example: “dinner at eight pm”.

Type the following at the terminal:

python3 stegsnow.py -m “dinner at eight pm” okonomiyaki.txt secret.txt

Table 1 Running the program when encoding a secret message

Decoding a secret message

Type the following at the terminal:

python3 stegsnow.py secret.txt

Table 2 Running the program when decoding a secret message

Representing characters as binary

Creating the secret message relies on some facts about the way that characters are represented in the computer. Computers represent all information as a series of 0s and 1s or binary. Characters are represented by a set of commonly used binary numbers. The mapping of characters to numbers is known as ASCII which stands for American Standard Code for Information Interchange. Some characters and the mapping to binary numbers are shown in the table below.

In stegsnow.py there is a dictionary, CHAR_TO_BINARY, that contains a mapping from a character to binary:

CHAR_TO_BINARY = { # binary representation of ASCII characters 'a': '1100001',

'b': '1100010',

'c': '1100011',

'd': '1100100',

'e': '1100101',

'f': '1100110',

'g': '1100111', ….

and another dictionary BINARY_TO_CHAR, that contains a mapping from binary to character:

BINARY_TO_CHAR = { # binary string to ascii characters '1100001': 'a',

'1100010': 'b',

'1100011': 'c',

'1100100': 'd',

'1100101': 'e',

'1100110': 'f',

'1100111': 'g', ….

Functionality

The skeleton code contains the empty functions: encode_secret_message() and decode_secret_message() you must complete them according to the instructions here and the specification in the docstrings (comments) at the start of the functions.

1) Function encode_secret_message(message, infile, outfile, zero, one)

In this function you will take the secret message, encode it as a series of 1s and 0s, combine it with the input file and write the result to the output file. Here is an example, let’s say your secret message is “dinner at eight pm” and the input file is the file that is distributed with the coursework.

a) Process the secret message character by character, producing a list of binary strings. Use the dictionary

CHAR_TO_BINARY.

b) Read the input file, infile, line by line.

c) Combine each line of the input file with one of the binary strings representing the secret message and write the result to the output file.

You may need to decompose this function further, writing more functions. Make sure you document your functions with docstrings.

You are probably thinking that this secret message is not very secret. Don’t worry! Once you have everything

working, you will attend to this detail.

2) Function decode_secret_message(infile, zero, one)

In this function you will take the file with file name infile, decode the secret message inside and then print it. To do this, you will need to complete these sub-tasks:

a) For each line in the file, extract the last 7 characters. Check that the last 7 characters is composed of zeroes and ones. Use the values passed in as parameters to the function to do this. If the 7 characters is composed of zeroes and ones you have a binary string representing a character in your secret message.

b) Convert every binary string extracted to a character by using the dictionary BINARY_TO_CHAR. Add the characters to a list.

c) You have your secret message, print it.

You may need to decompose this function further, writing more functions. Make sure you document your functions with docstrings.

3) Making your message invisible

So far the message has been entirely visible, anyone intercepting the message will be able to see it and easily guess at its meaning. What if we replaced every occurrence of a ‘1’ and a ‘0’ with different invisible characters such as a space and a tab? Well then our message would disappear. There are two constants at the top of the program:

ZERO = '0' # Character representing zero ``

ONE = '1' # Character representing one

These are used in main() and passed as parameters to encode_secret_message() and decode_secret_message().

You can change the values for the constants so that:

ZERO = '\t' # Character representing zero `` ONE = ' ' # Character representing one

a) Function encode_secret_message()

In this function you translated the letters in the message to binary strings. This won’t change but now you must also translate each digit in the binary string using the parameters passed to the function zero and one. You have been provided with the function encode(binary_letter, zero, one) which you can use to do this. In this way, you can replace the pattern of zeroes and ones in the binary letter with symbols that you can’t see such as a space and a tab.

'1100001' would be translated as ' \t\t\t\t ' '1100010' would be translated as ' \t\t\t\ \t'

b) Function decode_secret_message()

In this function you translated the binary strings in the file to ASCII characters. Once again, there’s a little more that we need to do. When you process the last 7 characters on a line you must translate the characters from, say, spaces and tabs to zeroes and ones. Use the parameters zero and one which are passed as parameters to the function. You have been provided with the function decode(binary_letter, zero_char, one_char), use it to translate what you get from the file to a string of binary digits. If a tab character represents ‘0’ and a space represents ‘1’ then:

' \t\t\t\t ' would be translated as   '1100001' ' \t\t\t\ \t' would be translated as '1100010'

That’s it. The coursework is finished.

Testing:

You are responsible for testing your program carefully. Make sure that you have thought about all the things that can go wrong and test your program to ensure that you know it works correctly in all circumstances.

Submitting your assignment

At the submission link on moodle:

1. Make sure your student number (not your name) is included in comments at the top of your program.

2. Upload your program.

a. You may upload multiple files but do not upload a folder containing your files because this can cause compatibility issues for the marking team.

3. You must ensure that your program works properly either on your own computer or on the CoCalc platform before you submit the code. 

Assessment

You are expected to show that you can code competently using the programming concepts covered so far in the course including (but not limited to): use of files, strings, variables, conditions, loops and functions.

Marking criteria will include:

Correctness – your code must perform as specified

You must apply the Python concepts appropriately.

Programming style – see section ‘Style Guide’ for more detail.

Your assignment will be marked using the rubric at the end of this document. This is the standard rubric used in the Department of Computer Science. Marks for your project work will be awarded for the capabilities (i.e. functional requirements) your system achieves, and the quality of the code. Categories 5 and 6 will be used for coding assignments.

Additional Challenges

Additional marks may also be gained by taking on extra challenges but you should only attempt an additional challenge if you have satisfied all requirements for the coursework. It’s up to you what you choose to do - if anything.

Note: You are strongly encouraged to follow the specification carefully and to use programming techniques as described in the course materials and textbooks. Poor quality code with additional functionality will not improve your marks.

Options for this coursework might include:

1. Write some unit tests for the functions you have written. You can write your own tests in a separate program using python or use doctest or unittest or pytest.

2. Change the encryption / decryption algorithm so that the start and end of the encrypted message starts and ends with a special character that cannot appear in the text. For example: the binary sequence ‘0000000’ could be used.

3. The brief specifies that you encode one letter (ascii character) per line. Amend your application so that multiple ascii characters can be encoded, up to a specified maximum line length. The maximum line length should be a constant in your program.

4. Take a look at the features of snow, can you add encryption / decryption using a Python cryptography library?

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. 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

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme