[Solved] Exercise 40 Modify Two Cipher Programs Given Chapter 4 Page 108 Use Functions Work Include Q37177168
Exercise 4.0 Modify the two cipher programs given in chapter 4(page 108) to use functions. This work should include themodifications you made to the programs in Homework 3. You shouldinclude three functions in the encrypt program for data collection,data verification and encryption. You should include two functionsin the decrypt program for input/verify the coded text/distance anddecrypting the code. There should be two programs turned in forthis problem (encrypt.py and decrypt.py).
Modified programs:
#exercise 3.0
#encrypt
plainText = input(“Enter text you would like to be encrypted:”)
distance = int(input(“Enter the distance value: “))
code = “”
for ch in plainText:
ordvalue = ord(ch)
cipherValue = ordvalue + distance
if cipherValue > ord(‘~’): #~
cpherValue = ord(‘ ‘) + distance –
(ord(‘~’) – ordvalue + 1)
code += chr(cipherValue)
print(code)
#exercise 3.0
#decrypt
code = input(“Enter the coded text: “)
distance = int(input(“Enter the distance value: “))
plainText = “”
for ch in code:
ordvalue = ord(ch)
cipherValue = ordvalue – distance
if cipherValue < ord(‘ ‘):
cipherValue = ord(‘~’) –
(distance – (ord(‘ ‘) – ordvalue – 1))
plainText += chr(cipherValue)
print(plainText)
Expert Answer
Answer to Exercise 4.0 Modify the two cipher programs given in chapter 4 (page 108) to use functions. This work should include the… . . .
OR

