\[ \begin{align}\begin{aligned}\newcommand\blank{~\underline{\hspace{1.2cm}}~}\\% Bold symbols (vectors) \newcommand\bs[1]{\mathbf{#1}}\\% Differential \newcommand\dd[2][]{\mathrm{d}^{#1}{#2}} % use as \dd, \dd{x}, or \dd[2]{x}\\% Poor man's siunitx \newcommand\unit[1]{\mathrm{#1}} \newcommand\num[1]{#1} \newcommand\qty[2]{#1~\unit{#2}}\\\newcommand\per{/} \newcommand\squared{{}^2} \newcommand\cubed{{}^3} % % Scale \newcommand\milli{\unit{m}} \newcommand\centi{\unit{c}} \newcommand\kilo{\unit{k}} \newcommand\mega{\unit{M}} % % Percent \newcommand\percent{\unit{\%}} % % Angle \newcommand\radian{\unit{rad}} \newcommand\degree{\unit{{}^\circ}} % % Time \newcommand\second{\unit{s}} \newcommand\s{\second} \newcommand\minute{\unit{min}} \newcommand\hour{\unit{h}} % % Distance \newcommand\meter{\unit{m}} \newcommand\m{\meter} \newcommand\inch{\unit{in}} \newcommand\foot{\unit{ft}} % % Force \newcommand\newton{\unit{N}} \newcommand\kip{\unit{kip}} % kilopound in "freedom" units - edit made by Sri % % Mass \newcommand\gram{\unit{g}} \newcommand\g{\gram} \newcommand\kilogram{\unit{kg}} \newcommand\kg{\kilogram} \newcommand\grain{\unit{grain}} \newcommand\ounce{\unit{oz}} % % Temperature \newcommand\kelvin{\unit{K}} \newcommand\K{\kelvin} \newcommand\celsius{\unit{{}^\circ C}} \newcommand\C{\celsius} \newcommand\fahrenheit{\unit{{}^\circ F}} \newcommand\F{\fahrenheit} % % Area \newcommand\sqft{\unit{sq\,\foot}} % square foot % % Volume \newcommand\liter{\unit{L}} \newcommand\gallon{\unit{gal}} % % Frequency \newcommand\hertz{\unit{Hz}} \newcommand\rpm{\unit{rpm}} % % Voltage \newcommand\volt{\unit{V}} \newcommand\V{\volt} \newcommand\millivolt{\milli\volt} \newcommand\mV{\milli\volt} \newcommand\kilovolt{\kilo\volt} \newcommand\kV{\kilo\volt} % % Current \newcommand\ampere{\unit{A}} \newcommand\A{\ampere} \newcommand\milliampereA{\milli\ampere} \newcommand\mA{\milli\ampere} \newcommand\kiloampereA{\kilo\ampere} \newcommand\kA{\kilo\ampere} % % Resistance \newcommand\ohm{\Omega} \newcommand\milliohm{\milli\ohm} \newcommand\kiloohm{\kilo\ohm} % correct SI spelling \newcommand\kilohm{\kilo\ohm} % "American" spelling used in siunitx \newcommand\megaohm{\mega\ohm} % correct SI spelling \newcommand\megohm{\mega\ohm} % "American" spelling used in siunitx % % Inductance \newcommand\henry{\unit{H}} \newcommand\H{\henry} \newcommand\millihenry{\milli\henry} \newcommand\mH{\milli\henry} % % Power \newcommand\watt{\unit{W}} \newcommand\W{\watt} \newcommand\milliwatt{\milli\watt} \newcommand\mW{\milli\watt} \newcommand\kilowatt{\kilo\watt} \newcommand\kW{\kilo\watt} % % Energy \newcommand\joule{\unit{J}} \newcommand\J{\joule} % % Composite units % % Torque \newcommand\ozin{\unit{\ounce}\,\unit{in}} \newcommand\newtonmeter{\unit{\newton\,\meter}} % % Pressure \newcommand\psf{\unit{psf}} % pounds per square foot \newcommand\pcf{\unit{pcf}} % pounds per cubic foot \newcommand\pascal{\unit{Pa}} \newcommand\Pa{\pascal} \newcommand\ksi{\unit{ksi}} % kilopound per square inch \newcommand\bar{\unit{bar}} \end{aligned}\end{align} \]

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.

Table 12.35 Test Cases#

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

Table 12.36 Deliverables#

Deliverables

Description

tp2_team_2_teamnumber.py

Your completed Python code.

tp2_team_2_teamnumber.pdf

Flowchart(s) for this task.