Feb 17, 2025 | 322 words | 3 min read
12.2.2. Task 2#
Learning Objectives#
Understand and implement different cipher algorithms for encrypting messages.
Convert text strings to binary strings.
Task Instructions#
Save the flowcharts for each of your tasks in tp2_team_2_teamnumber.pdf You will also need to include these flowcharts in your final report.
Create a function that uses the Beaufort cipher to encrypt a string. The function should take two arguments: the plaintext message to be encrypted and the key. It should return the encrypted ciphertext message. You can find details on this cipher in Beaufort Cipher.
Next, create a function that takes a message string, a starting sequence string, and an ending sequence string as arguments. It should generate and return a single binary string that consists of the starting sequence, followed by the message, and then by the ending sequence, all converted to binary strings. For example, with a starting sequence of “0”, a message string “Hi”, and an ending sequence “1”, the function would convert the starting sequence to “00110000”, the message to “01001000 01101001”, and the ending sequence to “00110001”. The function would then return “00110000 01001000 01101001 00110001”.
Finally, create a main
function in your Python program that uses
the functions described above to encrypt a message, and then convert the ciphertext into
a binary message. Your main
function should prompt the user to enter a
plaintext message, a key, a start sequence, and an end sequence, and then display both
the ciphertext and the binary message.
Save your program as tp2_team_2_teamnumber.py.
Sample Output#
Use the values in Table 12.35 below to test your program.
Case |
plaintext |
key |
start sequence |
end sequence |
---|---|---|---|---|
1 |
Hi |
secret |
0 |
1 |
2 |
eng 133 |
secret |
7 |
7 |
3 |
eng 133 |
SECRET |
7 |
7 |
4 |
Hide this message |
password |
007 |
700 |
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 tp2_team_2_teamnumber.py Enter the plaintext you want to encrypt: Hi Enter the key for Beaufort cipher: secret Enter the start sequence: 0 Enter the end sequence: 1 Encrypted Message using Beaufort Cipher: l6 Binary output message: 00110000 01101100 00110110 00110001
Case 2 Sample Output
$ python3 tp2_team_2_teamnumber.py Enter the plaintext you want to encrypt: eng 133 Enter the key for Beaufort cipher: secret Enter the start sequence: 7 Enter the end sequence: 7 Encrypted Message using Beaufort Cipher: o16 n0z Binary output message: 00110111 01101111 00110001 00110110 00100000 01101110 00110000 01111010 00110111
Case 3 Sample Output
$ python3 tp2_team_2_teamnumber.py Enter the plaintext you want to encrypt: eng 133 Enter the key for Beaufort cipher: SECRET Enter the start sequence: 7 Enter the end sequence: 7 Encrypted Message using Beaufort Cipher: o16 n0z Binary output message: 00110111 01101111 00110001 00110110 00100000 01101110 00110000 01111010 00110111
Case 4 Sample Output
$ python3 tp2_team_2_teamnumber.py Enter the plaintext you want to encrypt: Hide this message Enter the key for Beaufort cipher: password Enter the start sequence: 007 Enter the end sequence: 700 Encrypted Message using Beaufort Cipher: i2po 5k57 goe6r7l Binary output message: 00110000 00110000 00110111 01101001 00110010 01110000 01101111 00100000 00110101 01101011 00110101 00110111 00100000 01100111 01101111 01100101 00110110 01110010 00110111 01101100 00110111 00110000 00110000
Deliverables |
Description |
---|---|
tp2_team_2_teamnumber.py |
Your completed Python code. |
tp2_team_2_teamnumber.pdf |
Flowchart(s) for this task. |