Mar 14, 2025 | 498 words | 5 min read
13.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_2_teamnumber.pdf. You will also need to include these flowcharts in your final report.
Step 1: Binary Extraction Function#
Review your function from Section 11.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, Beaufort, Caesar, and Rail Fence, 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. For Rail Fence, the key must be a positive integer representing the number of rails. These functions should return the decrypted plaintext message. Details on each cipher are available at Section 12.1.1. You may want to start from the encryption functions you created in Section 12.2.2 and Section 13.1.1. Test your functions by encrypting and decrypting messages using the same key.
Note
Teams of 2 only need to implement the Beaufort cipher. Teams of 3 should implement the Beaufort cipher and one other cipher (either Rail Fence 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, Rail Fence, or Beaufort)
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 11.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 13.5 to test your code.
Save your program as tp3_team_2_teamnumber.py.
Image File Name |
Cipher |
Key |
Start Sequence |
End Sequence |
Plaintext |
|---|---|---|---|---|---|
Rail Fence |
2 |
7 |
4 |
Blue Topaz |
|
Rail Fence |
4 |
1 |
3 |
Emerald Green |
|
Beaufort |
glass |
55 |
55 |
crystal |
|
Beaufort |
Shine |
333 |
334 |
diamond |
|
Caesar |
169 |
5 |
1 |
Red Ruby |
|
Caesar |
777 |
40 |
04 |
Engineering |
Sample Output#
Use the values in Table 13.6 below to test your program.
Case |
cipher choice |
cipher key |
start_seq |
end_seq |
input image path |
|---|---|---|---|---|---|
1 |
rail fence |
2 |
7 |
4 |
ref_gry_r.png |
2 |
rail fence |
4 |
1 |
3 |
ref_col_r.png |
3 |
beaufort |
glass |
55 |
55 |
ref_gry_b.png |
4 |
beaufort |
Shine |
333 |
334 |
ref_col_b.png |
5 |
caesar |
169 |
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: rail fence Enter the key for the cipher: 2 Enter the start sequence: 7 Enter the end sequence: 4 Enter the path of the input image: ref_gry_r.png Extracted Binary Message: 01000010 01110101 00100000 01101111 01100001 01101100 01100101 01010100 01110000 01111010 Recovered Cipher Text: Bu oaleTpz Converted text: Blue Topaz
Case 2 Sample Output
$ python3 tp3_team_2_teamnumber.py Enter the cipher you want to use for encryption: rail fence Enter the key for the cipher: 4 Enter the start sequence: 1 Enter the end sequence: 3 Enter the path of the input image: ref_col_r.png Extracted Binary Message: 01000101 01100100 01101110 01101101 01101100 00100000 01100101 01100101 01100001 01000111 01100101 01110010 01110010 Recovered Cipher Text: Ednml eeaGerr Converted text: Emerald Green
Case 3 Sample Output
$ python3 tp3_team_2_teamnumber.py Enter the cipher you want to use for encryption: beaufort Enter the key for the cipher: glass Enter the start sequence: 55 Enter the end sequence: 55 Enter the path of the input image: ref_gry_b.png Extracted Binary Message: 01100101 00110100 01101101 01100001 00111001 01100111 01100001 Recovered Cipher Text: e4ma9ga Converted text: crystal
Case 4 Sample Output
$ python3 tp3_team_2_teamnumber.py Enter the cipher you want to use for encryption: beaufort Enter the key for the cipher: Shine Enter the start sequence: 333 Enter the end sequence: 334 Enter the path of the input image: ref_col_b.png Extracted Binary Message: 01110000 00111001 01101001 01100010 00110000 01100110 01100101 Recovered Cipher Text: p9ib0fe Converted text: diamond
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: 169 Enter the start sequence: 5 Enter the end sequence: 1 Enter the path of the input image: ref_gry_c.png Extracted Binary Message: 01000101 01110010 01110001 00100000 01000101 01101000 01101111 01101100 Recovered Cipher Text: Erq Ehol Converted text: Red Ruby
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: 01000010 01101011 01100100 01100110 01101011 01100010 01100010 01101111 01100110 01101011 01100100 Recovered Cipher Text: Bkdfkbbofkd Converted text: Engineering
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: 01000010 01101011 01100100 01100110 01101011 01100010 01100010 01101111 01100110 01101011 01100100 Recovered Cipher Text: Bkdfkbbofkd Converted text: Dmfhmddqhmf
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.
Deliverables |
Description |
|---|---|
tp3_team_2_teamnumber.py |
Your completed Python code. |
tp3_team_2_teamnumber.pdf |
Flowchart(s) for this task. |