python 辅导、辅导Steganography. Assignment、辅导python、辅导binary Python
- 首页 >> Python编程CS代写做之-C++ Programming And Software Engineering II
Project 2 - Steganography
Due Sunday by 11:59pm Points 50 Submitting a file upload File Types py
Submit Assignment
Overview
In this assignment, you will be using steganography (https://en.wikipedia.org/wiki/Steganography) to hide a
message inside of a text document. There are many, many forms of steganography, but they share a
common theme: hiding a secret message inside of another message. This can include hiding data in
images or video files, or can hide data in text by using strange Unicode characters.
We will be using a simpler scheme which hides a message using capitalization in a piece of text.
How to Hide a Message
To hide a message, we need two things: a secret message, and data to hide it in. The binary
representation of the secret message will determine which characters to capitalize, and which ones to uncapitalize.
First, take the input message and convert it to binary. Our message will consist of only ASCII characters,
which fit into seven bits, so each character of the input message will be converted into seven bits. The end
of the message will be marked with the null character, which is a special ASCII value with integer value 0
that is often used to mark the end of messages.
For example, consider the secret message "hello"; its binary encoding is:
message: h e l l o <END>
int message: 104 101 108 108 111 0
binary message: 1101000 1100101 1101100 1101100 1101111 0000000
Next, we use this binary string to set the case of letters in the output string:
binary message: 110100011001011101100110110011011110000000
original data: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
modified data: AAaAaaaAAaaAaAAAaAAaaAAaAAaaAAaAAAAaaaaaaa
However, some characters (like punctuation and spaces) do not have any case! These should be skipped
whenever encountered. They should still be present in the output, but without any conversion. For
example:
binary string: 1101 00 0 110010111 011001 10110011 0111100 00000
original data: This is a perfectly normal sentence. Nothing interesting to see here.
modified data: THiS is a PErfEcTLY nORmaL SeNTenCE. nOTHIng interesting to see here.
Decoding a message is the same process in reverse. We extract binary digits based on the case of letters
until we find the end marker, then we convert those binary digits back into characters:
data: A PErfECTLy nOrMAL and UNINTerEsTIng SeNTENcE witH no hiDden message inside.
case: 1 110011110 010111 000 1111100101100 10111101 0001 00 001000 0000
grouped: 1110011 1100101 1100011 1110010 1100101 1110100 0100001 0000000
ints: 115 101 99 114 101 116 33 0
message: s e c r e t ! <END>
What to Do
Create a file named steganography.py. Add a comment at the top of this file containing your name, student
id number, and a brief description of the program.
In this script, you'll write two functions: encode(...) and decode(...). These functions will perform the
encoding and decoding process as described above. Each of your functions should have a docstring briefly
describing itself.
Encode Details
encode(...) should have two parameters: the secret message, and the data to hide it in. It should return a
string, which is a copy of data with the message hidden in it. Remember, you'll need to:
1. Convert each character of the secret message to 7-bit binary
2. Set the case of letters in the output based on that binary message
3. Leave characters without case unchanged (anything that's not an ASCII letter)
Decode Details
decode(...) should have a single parameter: a string to decode from. It should return a string containing the
secret message. Remember, this is just the encoding process in reverse, so you'll need to:
1. Extract a binary string based on the case of letters in the string, skipping non-letters
2. Break this string into 7-bit binary values
3. Convert those binary values back into characters
4. Stop when you reach the null character, which has the integer value 0
Hints
1. There are several ways to handle conversion between ints and binary. You can use format strings, or
Project 2 - Rubric
look into options for the int(...) and bin(...) functions.
2. You can convert between characters and integers using the ord(...) and chr(...) functions.
3. The module string (https://docs.python.org/2/library/string.html) has some useful constants
4. The type str (https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str) has several useful
methods for converting case
What to Submit
When you are finished, upload your file steganography.py to Canvas.
Total Points: 50.0
Criteria Ratings Pts
2.0 pts
8.0 pts
2.0 pts
9.0 pts
9.0 pts
2.0 pts
9.0 pts
9.0 pts
Comment at beginning
Required comment appears at the beginning of the script, containing the student's name, id,
and a short description of the program.
Coding Style
Comments are used well to explain the code. Variables are named reasonably. Indentation
matches expectations. Named constants are used instead of placing values directly into the
code. Code is generally readable.
Encode function docstring
Encode function has a docstring briefly describing itself.
Encode converts secret message to binary
Encode converts each character of the secret message into its 7-bit ASCII representation. Adds
the null-terminator to the end of the message.
Encode uses binary secret message to set case
Encode function uses the binary secret message to set the case of characters in the output
message. Skips non-letter characters, leaving them unchanged in the output. Leaves characters
of the original message unchanged if there is no conversion to be done.
Decode function docstring
Decode function has a docstring briefly describing itself.
Decode function extracts binary
Decode function extracts the binary representation from the case of characters in the given
data. Skips non-letter characters.
Decode function converts binary to characters
Decode function breaks the binary string into 7-bit binary values, converts those values into
characters, combines those characters into a string, and stops when the null-terminator is
reached.