Dec 03, 2024 | 545 words | 5 min read
11.1.1. Task 1#
Learning Objectives#
Encrypt a plaintext into ciphertext.
Encode the ciphertext into an image at a specified bit offset.
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: Encryption Functions#
Similarly to the Vigenère cipher, you implemented in Section 10.2.2, create functions that use the XOR and Caesar cipher to encrypt a string. The functions should take two arguments: the plaintext message to be encrypted and the key. For the Caesar cipher, the key should be an integer representing the shift value. These functions should return the encrypted ciphertext message. You can find details on the XOR and Caesar ciphers in Section 10.1.1.
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 2: Encoding Function#
Update the encoding function you wrote in Section 10.2.3 to embed the binary message into an image, so that it can insert the binary message at a specified bit offset. For example, if the offset is 5, the function should start encoding the message after the 5th bit of the image.
Step 3: Main Function#
Create a main
function that collects the following inputs from the user:
a choice of encryption method (Caesar, XOR, or Vigenère)
a plaintext message
an encryption key
the message start sequence
the message end sequence
the bit offset for encoding the message
the path to an input image file
the path to an output image file
the path to a comparison image file
The function should encrypt the message using the chosen cipher, add the start and end sequences to the message, then convert the encrypted message to binary, and encode it into the image at the specified bit offset.
If the encoding is not successful, the main
function should display an error
message and stop. Otherwise, it should display a success message to the user and save
and display the modified image.
Finally, building on the image comparison function you wrote in
Section 10.2.1, the main
function should compare the modified
image with the comparison image, displaying the resulting image difference and printing
whether the images are the same or different.
Use the files provided in the Table 11.13 to test your code.
Save your program as tp3_team_1_teamnumber.py.
Image File Name |
Cipher |
Key |
Plaintext |
Start Sequence |
End Sequence |
Bit Offset |
---|---|---|---|---|---|---|
None |
None |
None |
None |
None |
None |
|
None |
None |
None |
None |
None |
None |
|
XOR |
3RR0R |
Sunny |
12 |
21 |
13 |
|
XOR |
happy |
ENGR 133 |
44 |
77 |
18 |
|
Vigenère |
Up! |
Boiler |
22 |
88 |
2 |
|
Vigenère |
is fun |
Math 101 |
31 |
&& |
15 |
|
Caesar |
159 |
Red Rose |
5 |
1 |
11 |
|
Caesar |
777 |
Love ENGR |
40 |
04 |
9 |
Sample Output#
Use the values in Table 11.14 below to test your program.
Case |
cipher choice |
plaintext |
cipher key |
start_seq |
end_seq |
bit offset |
input image path |
output image path |
compare image path |
---|---|---|---|---|---|---|---|---|---|
1 |
xor |
Sunny |
3RR0R |
12 |
21 |
13 |
ref_gry.png |
gry_x.png |
ref_gry_x.png |
2 |
xor |
ENGR 133 |
happy |
44 |
77 |
18 |
ref_col.png |
col_x.png |
ref_col_x.png |
3 |
vigenere |
Boiler |
Up! |
22 |
88 |
2 |
ref_gry.png |
gry_v.png |
ref_gry_v.png |
4 |
vigenere |
Math 101 |
is fun |
31 |
&& |
15 |
ref_col.png |
col_v.png |
ref_col_v.png |
5 |
caesar |
Red Rose |
159 |
5 |
1 |
11 |
ref_gry.png |
gry_c.png |
ref_gry_c.png |
6 |
caesar |
Love ENGR |
777 |
40 |
04 |
9 |
ref_col.png |
col_c.png |
ref_col_c.png |
7 |
caesar |
Love ENGR |
778 |
40 |
04 |
9 |
ref_col.png |
col_c.png |
ref_col_c.png |
8 |
caesar |
Love ENGR |
777 |
40 |
04 |
25 |
ref_col.png |
col_c.png |
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_1_teamnumber.py Enter the cipher you want to use for encryption: xor Enter the plaintext you want to encrypt: Sunny Enter the key for the cipher: 3RR0R Enter the start sequence: 12 Enter the end sequence: 21 Enter the bit offset before you want to start encoding: 13 Enter the path of the input image: ref_gry.png Enter the path for your encoded image: gry_x.png Enter the path of the image you want to compare: ref_gry_x.png Encrypted Message using XOR Cipher: `'<^+ Binary output message: 00110001 00110010 01100000 00100111 00111100 01011110 00101011 00110010 00110001 Message successfully encoded and saved to: gry_x.png The images are the same.
Case 2 Sample Output
$ python3 tp3_team_1_teamnumber.py Enter the cipher you want to use for encryption: xor Enter the plaintext you want to encrypt: ENGR 133 Enter the key for the cipher: happy Enter the start sequence: 44 Enter the end sequence: 77 Enter the bit offset before you want to start encoding: 18 Enter the path of the input image: ref_col.png Enter the path for your encoded image: col_x.png Enter the path of the image you want to compare: ref_col_x.png Encrypted Message using XOR Cipher: -/7"YYRC Binary output message: 00110100 00110100 00101101 00101111 00110111 00100010 01011001 01011001 01010010 01000011 00110111 00110111 Message successfully encoded and saved to: col_x.png The images are the same.
Case 3 Sample Output
$ python3 tp3_team_1_teamnumber.py Enter the cipher you want to use for encryption: vigenere Enter the plaintext you want to encrypt: Boiler Enter the key for the cipher: Up! Enter the start sequence: 22 Enter the end sequence: 88 Enter the bit offset before you want to start encoding: 2 Enter the path of the input image: ref_gry.png Enter the path for your encoded image: gry_v.png Enter the path of the image you want to compare: ref_gry_v.png Encrypted Message using Vigenère Cipher: Vdcftl Binary output message: 00110010 00110010 01010110 01100100 01100011 01100110 01110100 01101100 00111000 00111000 Message successfully encoded and saved to: gry_v.png The images are the same.
Case 4 Sample Output
$ python3 tp3_team_1_teamnumber.py Enter the cipher you want to use for encryption: vigenere Enter the plaintext you want to encrypt: Math 101 Enter the key for the cipher: is fun Enter the start sequence: 31 Enter the end sequence: && Enter the bit offset before you want to start encoding: 15 Enter the path of the input image: ref_col.png Enter the path for your encoded image: col_v.png Enter the path of the image you want to compare: ref_col_v.png Encrypted Message using Vigenère Cipher: Usmm 489 Binary output message: 00110011 00110001 01010101 01110011 01101101 01101101 00100000 00110100 00111000 00111001 00100110 00100110 Message successfully encoded and saved to: col_v.png The images are the same.
Case 5 Sample Output
$ python3 tp3_team_1_teamnumber.py Enter the cipher you want to use for encryption: caesar Enter the plaintext you want to encrypt: Red Rose Enter the key for the cipher: 159 Enter the start sequence: 5 Enter the end sequence: 1 Enter the bit offset before you want to start encoding: 11 Enter the path of the input image: ref_gry.png Enter the path for your encoded image: gry_c.png Enter the path of the image you want to compare: ref_gry_c.png Encrypted Message using Caesar Cipher: Uhg Urvh Binary output message: 00110101 01010101 01101000 01100111 00100000 01010101 01110010 01110110 01101000 00110001 Message successfully encoded and saved to: gry_c.png The images are the same.
Case 6 Sample Output
$ python3 tp3_team_1_teamnumber.py Enter the cipher you want to use for encryption: caesar Enter the plaintext you want to encrypt: Love ENGR Enter the key for the cipher: 777 Enter the start sequence: 40 Enter the end sequence: 04 Enter the bit offset before you want to start encoding: 9 Enter the path of the input image: ref_col.png Enter the path for your encoded image: col_c.png Enter the path of the image you want to compare: ref_col_c.png Encrypted Message using Caesar Cipher: Ilsb BKDO Binary output message: 00110100 00110000 01001001 01101100 01110011 01100010 00100000 01000010 01001011 01000100 01001111 00110000 00110100 Message successfully encoded and saved to: col_c.png The images are the same.
Case 7 Sample Output
$ python3 tp3_team_1_teamnumber.py Enter the cipher you want to use for encryption: caesar Enter the plaintext you want to encrypt: Love ENGR Enter the key for the cipher: 778 Enter the start sequence: 40 Enter the end sequence: 04 Enter the bit offset before you want to start encoding: 9 Enter the path of the input image: ref_col.png Enter the path for your encoded image: col_c.png Enter the path of the image you want to compare: ref_col_c.png Encrypted Message using Caesar Cipher: Jmtc CLEP Binary output message: 00110100 00110000 01001010 01101101 01110100 01100011 00100000 01000011 01001100 01000101 01010000 00110000 00110100 Message successfully encoded and saved to: col_c.png The images are different.
Case 8 Sample Output
$ python3 tp3_team_1_teamnumber.py Enter the cipher you want to use for encryption: caesar Enter the plaintext you want to encrypt: Love ENGR Enter the key for the cipher: 777 Enter the start sequence: 40 Enter the end sequence: 04 Enter the bit offset before you want to start encoding: 25 Enter the path of the input image: ref_col.png Enter the path for your encoded image: col_c.png Enter the path of the image you want to compare: ref_col_c.png Given message is too long to be encoded in the image. Encrypted Message using Caesar Cipher: Ilsb BKDO Binary output message: 00110100 00110000 01001001 01101100 01110011 01100010 00100000 01000010 01001011 01000100 01001111 00110000 00110100