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".
write a program for the decryption of 2-rail fence cipher. For example, the input "Cmhmtmrooeoeoorw" should...
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". in python
Python linked lists ● Insert: this method takes a value as a parameter, and adds a...
Python linked lists ● Insert: this method takes a value as a parameter, and adds a node which contains the value to the end of the linked list ● Delete: this method deletes a node from the linked list. If an index is passed as a parameter, then the method should delete the node at this index. If no index is passed, then delete the first item in the list ● Find: this method takes a value as a parameter,...
Write a static method called "evaluate" that takes a string as a parameter
In Java language  Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the expression evaluates to. The method MUST use a stack...
In an application write a method filterStack that takes a stack of integers as a parameter...
In an application write a method filterStack that takes a stack of integers as a parameter and filters its elements (in a new Stack) in a way that places the even elements at the bottom and the odd ones at the top. The original stack should remain unchanged. You should use a queue (only one queue) as a temporary storage. Use stack and queue operations only to solve this problem. No need to write the main method. For example, if...
Can someone do this python program? Write a function that takes a number as a parameter...
Can someone do this python program? Write a function that takes a number as a parameter and then prints out all of the factors for that number.
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints...
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints a message with information about the total amount owed and how much the tip was. As a reminder, the tip amounts are 10%, 15% and 20% for stingy, regular, and generous customers. And the tax amount should be 7%. The total amount is calculated as the sum of two amounts: check_amount = base_cost*1.07 tip_amount = tip_percentage*check_amount To receive full credit, you must use string...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT