Question: The Caesar Cipher for Encryption(Python): Step 1 Write the function cipher chr() to encrypt a single clear text character using any arbitrary offset and the
The Caesar Cipher for Encryption(Python): Step 1
Write the function cipher chr() to encrypt a single clear text character using any arbitrary offset and the modulo function so that the cipher text character always has a value between 32 and 126, inclusive. This function should return the cipher text character. Dont forget to include docstrings.
The correct behavior of this function is shown below:
cipher_chr(A, 1) # A with an offset of 1.
B
cipher_chr(A, 5) # A with an offset of 5.
F
cipher_chr(, 1) # with an offset of 1.
cipher_chr(, 2) # with an offset of 2.
'!'
The Caesar Cipher for Encryption: Step 2
Write a function called clear2cipher() that takes two arguments, a clear text string to cipher and an offset, and returns a cipher text string. First import your cipher chr() function. Then start your clear2cipher function by initializing an empty string accumulator. Use a for-loop to cycle through each character of the clear text, ciphering each character by calling cipher chr() and concatenating the ciphered character to the accumulator as you go.
The following demonstrates the proper behavior of this function:
# Import cipher_chr().
from cipher_chr import *
line = Spontaneity has its time and place.
clear2cipher(line, 5)
Xutsyfsjny%mfx%nyx%ynrj%fsi%uqfhj3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
