Dec 03, 2024 | 469 words | 5 min read
11.1.2. Task 2#
Learning Objectives#
Extract a hidden binary message from an image using the Least Significant Bit (LSB) technique.
Recover the ciphertext and plaintext message.
Task Instructions#
Save the flowcharts for each of your tasks in tp3_team_teamnumber.pdf. You will also need to include these flowcharts in your final report.
Step 1: Binary Extraction Function#
Review your function from Section 9.2.2 that extracts binary data from the least significant bit of each pixel in an image. Previously, the encoded message started at the first bit in the image. Now, the message will start at a random bit offset. Update your function if necessary to ensure it can extract the message regardless of any offset.
Step 2: Decryption Functions#
For each of the ciphers, Vigenère, Caesar, and XOR, create a function that decrypts ciphertext into plaintext. The functions should take two arguments: the ciphertext message and the key. For the Caesar cipher, the key should be an integer representing the shift value. These functions should return the decrypted plaintext message. Details on each cipher are available at Section 10.1.1. You may want to start from the encryption functions you created in Section 10.2.2 and Section 11.1.1. Test your functions by encrypting and decrypting messages using the same key.
Note
Teams of 2 only need to implement the Vigenère cipher. Teams of 3 should implement the Vigenère cipher and one other cipher (either XOR or Caesar). Teams of 4 or more should implement all three ciphers.
Step 3: Main Function#
Create a main
function that collects the following inputs from the user:
a choice of decryption method (Caesar, XOR, or Vigenère)
a decryption key
the message start sequence
the message end sequence
the path to an input image file
The function should then:
Extract the binary message from the input image using the function you updated in Step 1: Binary Extraction Function.
Convert the binary to ciphertext. You can reuse the function you created in Section 9.2.3.
Decrypt the ciphertext to plaintext using the chosen cipher and one of the functions you wrote for Step 2: Decryption Functions.
Display the binary message, ciphertext, and plaintext to the user.
Use the files provided in the Table 11.15 to test your code.
Save your program as tp3_team_2_teamnumber.py.
Image File Name |
Cipher |
Key |
Start Sequence |
End Sequence |
Plaintext |
---|---|---|---|---|---|
XOR |
3RR0R |
12 |
21 |
Sunny |
|
XOR |
happy |
44 |
77 |
ENGR 133 |
|
Vigenère |
Up! |
22 |
88 |
Boiler |
|
Vigenère |
is fun |
31 |
&& |
Math 101 |
|
Caesar |
159 |
5 |
1 |
Red Rose |
|
Caesar |
777 |
40 |
04 |
Love ENGR |
Sample Output#
Use the values in Table 11.16 below to test your program.
Case |
cipher choice |
cipher key |
start_seq |
end_seq |
input image path |
---|---|---|---|---|---|
1 |
xor |
3RR0R |
12 |
21 |
ref_gry_x.png |
2 |
xor |
happy |
44 |
77 |
ref_col_x.png |
3 |
vigenere |
Up! |
22 |
88 |
ref_gry_v.png |
4 |
vigenere |
is fun |
31 |
&& |
ref_col_v.png |
5 |
caesar |
159 |
5 |
1 |
ref_gry_c.png |
6 |
caesar |
777 |
40 |
04 |
ref_col_c.png |
7 |
caesar |
778 |
40 |
04 |
ref_col_c.png |
8 |
caesar |
777 |
99 |
04 |
ref_col_c.png |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 tp3_team_2_teamnumber.py Enter the cipher you want to use for encryption: xor Enter the key for the cipher: 3RR0R Enter the start sequence: 12 Enter the end sequence: 21 Enter the path of the input image: ref_gry_x.png Extracted Binary Message: 0110000000100111001111000101111000101011 Converted Binary Text: `'<^+ Converted text: Sunny
Case 2 Sample Output
$ python3 tp3_team_2_teamnumber.py Enter the cipher you want to use for encryption: xor Enter the key for the cipher: happy Enter the start sequence: 44 Enter the end sequence: 77 Enter the path of the input image: ref_col_x.png Extracted Binary Message: 0010110100101111001101110010001001011001010110010101001001000011 Converted Binary Text: -/7"YYRC Converted text: ENGR 133
Case 3 Sample Output
$ python3 tp3_team_2_teamnumber.py Enter the cipher you want to use for encryption: vigenere Enter the key for the cipher: Up! Enter the start sequence: 22 Enter the end sequence: 88 Enter the path of the input image: ref_gry_v.png Extracted Binary Message: 010101100110010001100011011001100111010001101100 Converted Binary Text: Vdcftl Converted text: Boiler
Case 4 Sample Output
$ python3 tp3_team_2_teamnumber.py Enter the cipher you want to use for encryption: vigenere Enter the key for the cipher: is fun Enter the start sequence: 31 Enter the end sequence: && Enter the path of the input image: ref_col_v.png Extracted Binary Message: 0101010101110011011011010110110100100000001101000011100000111001 Converted Binary Text: Usmm 489 Converted text: Math 101
Case 5 Sample Output
$ python3 tp3_team_2_teamnumber.py Enter the cipher you want to use for encryption: caesar Enter the key for the cipher: 159 Enter the start sequence: 5 Enter the end sequence: 1 Enter the path of the input image: ref_gry_c.png Extracted Binary Message: 0101010101101000011001110010000001010101011100100111011001101000 Converted Binary Text: Uhg Urvh Converted text: Red Rose
Case 6 Sample Output
$ python3 tp3_team_2_teamnumber.py Enter the cipher you want to use for encryption: caesar Enter the key for the cipher: 777 Enter the start sequence: 40 Enter the end sequence: 04 Enter the path of the input image: ref_col_c.png Extracted Binary Message: 010010010110110001110011011000100010000001000010010010110100010001001111 Converted Binary Text: Ilsb BKDO Converted text: Love ENGR
Case 7 Sample Output
$ python3 tp3_team_2_teamnumber.py Enter the cipher you want to use for encryption: caesar Enter the key for the cipher: 778 Enter the start sequence: 40 Enter the end sequence: 04 Enter the path of the input image: ref_col_c.png Extracted Binary Message: 010010010110110001110011011000100010000001000010010010110100010001001111 Converted Binary Text: Ilsb BKDO Converted text: Knud DMFQ
Case 8 Sample Output
$ python3 tp3_team_2_teamnumber.py Enter the cipher you want to use for encryption: caesar Enter the key for the cipher: 777 Enter the start sequence: 99 Enter the end sequence: 04 Enter the path of the input image: ref_col_c.png Start or end sequence not found in the image.