Question

In: Computer Science

Problem 2: Caesar Cipher Decryption] Write a python method that takes two parameters: A parameter of...

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):

Solutions

Expert Solution

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

  • Create a function which have two arguments( data,key)
  • create a new emptystring to store the deycrypted message
  • iterate through each letter in data and check whether uppercase or lower
  • according to if conditions decrement the ascii value of character by 'key' value
  • append the decrypted character to the result string(deycrpt)

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
  









Related Solutions

Caesar Cipher Encryption] Write a method that takes two parameters: A parameter of type str and...
Caesar Cipher Encryption] Write a 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. Convert the string into a list (let us refer to it as lista). An element in the generated list is the position of the corresponding letter in the parameter string in the English alphabet. Example: ‘C’...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The program should be able to handle different keys by deciding the key at run time. Thank you :)
please solve the following in python: write a program for the decryption of 2-rail fence cipher....
please solve the following in python: write a program for the decryption of 2-rail fence cipher. For example, the input "Cmhmtmrooeoeoorw" should return "Comehometomorrow", and input "topaesw lyr" should return "two players".
please solve the following in python: write a program for the decryption of 2-rail fence cipher....
please solve the following in python: write a program for the decryption of 2-rail fence cipher. For example, the input "Cmhmtmrooeoeoorw" should return "Comehometomorrow", and input "topaesw lyr" should return "two players".
The mathematical expression of the encryption and decryption process of a Caesar cipher algorithm is expressed...
The mathematical expression of the encryption and decryption process of a Caesar cipher algorithm is expressed respectively as: c=Ep, k=p+k%26                                                                                                                         (1) p=Dc,k=c-k%26                                                                                                                         (2) Please do the following: Write at least two paragraphs to explain the principle of operation of the algorithm. For a full credit, your explanation must show the architectural diagram of the encryption and decryption process. Write a program to implement the Caesar algorithm Code must have two functions; encryption and decryption Test your codes with p as...
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Python Problem 3 Write a function named enterNewPassword. This function takes no parameters. It prompts the...
Python Problem 3 Write a function named enterNewPassword. This function takes no parameters. It prompts the user to enter a password until the entered password has 8-15 characters, including at least one digit. Tell the user whenever a password fails one or both of these tests.
This is an intro to python question. #Write a function called search_for_string() that takes two #parameters,...
This is an intro to python question. #Write a function called search_for_string() that takes two #parameters, a list of strings, and a string. This function #should return a list of all the indices at which the #string is found within the list. # #You may assume that you do not need to search inside the #items in the list; for examples: # # search_for_string(["bob", "burgers", "tina", "bob"], "bob") # -> [0,3] # search_for_string(["bob", "burgers", "tina", "bob"], "bae") # -> []...
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT