In: Computer Science
Problem 2: Caesar Cipher Decryption] Write a python method that takes two parameters: A parameter of type str and a parameter of type int. The first parameter is the plaintext message, and the second parameter is the encryption key. The method strictly does the following tasks:
a. Reverse the operations performed by the encryption method to obtain the plaintext message.
The method’s header is as follows: def casesardecryption(s, key):
Here our task is to create a python program which consist of a
function called 'casesardecryption' which take 2 arguments which
are a string type and an integer type.When we call the function
with text and key it should return decrypted messege
ceaser cypher is a simple encription method in which cipher text is
obatained by changing the letters to a new letter which is 'KEY'
times infront of it in alphabetically.To decrypt the text select a
letter which is key times before it in alphabetically
things to remeber before coding
CODE
(Plaese read all commentss for better understanding of the
program)
SAMPLE RUN
I am also attaching the text version of the code in case you need to copy paste
def ceaserdecryption(data,key): #defining the ceaserdecryption
function
decrypt = "" #craeting a empty string to store decrypt
data
for i in range(len(data)): #loop that iterate
through each element in data
c = data[i]
# Encrypt uppercase
characters
if (c.isupper()):
decrypt +=
chr((ord(c) - key-65) % 26 + 65) #(ord () for convert to character
to ASCII)
# Encrypt lowercase
characters
else:
decrypt +=
chr((ord(c) - key - 97) % 26 + 97) #(chr() for convert ASCII value
to character)
print(" INPUT data :",data) #print statement
print(" Key :",key)
print(" Decrypted message :",decrypt)
key=2 #defining key
data= "ETARVQITCRJA" #data
ceaserdecryption(data,key) #calling function