Question
Write code in python Write the functions encrypt(message, key) and decrypt(message, key), where message is a string and key is an integer. Both functions return
Write code in python
Write the functions encrypt(message, key) and decrypt(message, key), where message is a string and key is an integer. Both functions return a string that contains message encrypted/decrypted using the Caesar cipher method. If a string is not provided as an input for message or an integer is not provided for key, the function must return an error message Invalid input
Functions must encrypt/decrypt both uppercase and lowercase letters
decrypt(message, key) retrieves the original message encrypted by the encrypt function if the same key is used
Numbers and punctuation can remain the same
Write the unit test script to perform your testing for both functions encrypt and decrypt using the unittest module and prove that they work properly. Remember to be as descriptive as possible and write as many cases as necessary.
def encrypt(message, key):
"""
Takes a string and an integer an returns the encrypted message
using the Caesar cipher method
>>> encrypt("Hello world",12)
'Tqxxa iadxp'
>>> encrypt("We are Penn State!!!",6)
'Ck gxk Vktt Yzgzk!!!'
>>> encrypt("We are Penn State!!!",5)
'Bj fwj Ujss Xyfyj!!!'
>>> encrypt(5.6,3)
'Invalid input'
>>> encrypt('Hello',3.5)
'Invalid input'
>>> encrypt(5.6,3.15)
'Invalid input'
"""
# --- YOU CODE STARTS HERE
# --- CODE ENDS HERE
def decrypt(message, key):
"""
Takes a string and an integer an returns the decrypted message
using the Caesar cipher method
>>> decrypt("Tqxxa iadxp",12)
'Hello world'
>>> decrypt("Ck gxk Vktt Yzgzk!!!",6)
'We are Penn State!!!'
>>> decrypt("Bj fwj Ujss Xyfyj!!!",5)
'We are Penn State!!!'
>>> decrypt(5.6,3)
'Invalid input'
>>> decrypt('Hello',3.5)
'Invalid input'
>>> decrypt(5.6,3.15)
'Invalid input'
"""
# --- YOU CODE STARTS HERE
# --- CODE ENDS HERE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started