Question

In: Computer Science

In PYTHON: Write a function that receives an encrypted string and decrypts it as follows. The...

In PYTHON:

Write a function that receives an encrypted string and decrypts it as follows. The decryption does not change the lowercase letters ‘e’, ‘w’, and ‘l’ (lowercase L). For any other character, we change it to a number using ord(). We then take the number to a power of 19, and then find the remainder after diving by 201. Finally, we take the character corresponding to the number we obtained (using chr()).

For example, assume that we receive the character ‘Â’, which corresponds to the number 194. We calculate the reminder when dividing 19419 by 201, obtaining 122. Using chr(), we find that this is the letter ‘z’.

Your function is not allowed to automatically replace every ‘Â’ with a ‘z’. Instead, it should separately perform the above calculation for each character in the encrypted text.

More details: Your function should handle one character at a time. For each character, turn it to a number, take it to the power of 19, find the remainder when dividing by 201, and turn back to a letter. Don’t forget the three lowercase letters that remain unchanged.

Solutions

Expert Solution

Code

def decryption(str):
decryptedString = ""
for i in range (0, len(str)):
if(str[i] == 'e' or str[i] == 'w' or str[i] == 'l'): #ignoring three lowercase letters
decryptedString = decryptedString + str[i]
continue
else:
num = ord(str[i]) # finding number associated with character
num = num ** 19 # raising power of 19 of number
num = num % 201 # taking mod with 201
decryptedString = decryptedString + chr(num) # forming final decrypted String
  
return decryptedString

str = "©lWe"
print("Encrpyted String: ", str)
print("Decrypted String: ", decryption(str))
    
  
Test Output

  


Related Solutions

Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks if ch is...
Python program.  from random import . Write a function called cleanLowerWord that receives a string as a...
Python program.  from random import . Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks...
In Python Create a function called ????. The function receives a "string" that represents a year...
In Python Create a function called ????. The function receives a "string" that represents a year (the variable with this "String" will be called uve) and a list containing "strings" representing bank accounts (call this list ????). • Each account is represented by 8 characters. The format of each account number is "** - ** - **", where the asterisks are replaced by numeric characters. o For example, “59-04-23”. • The two central characters of the "string" of each account...
Python: Write a function that receives a one dimensional array of integers and returns a Python...
Python: Write a function that receives a one dimensional array of integers and returns a Python tuple with two values - minimum and maximum values in the input array. You may assume that the input array will contain only integers and will have at least one element. You do not need to check for those conditions. Restrictions: No built-in Python data structures are allowed (lists, dictionaries etc). OK to use a Python tuple to store and return the result. Below...
In PYTHON: Write a function that receives a sentence and returns the last word of that...
In PYTHON: Write a function that receives a sentence and returns the last word of that sentence. You may assume that there is exactly one space between every two words, and that there are no other spaces at the sentence. To make the problem simpler, you may assume that the sentence contains no hyphens, and you may return the word together with punctuation at its end.
Write a Python function that takes a list of string as arguments. When the function is...
Write a Python function that takes a list of string as arguments. When the function is called it should ask the user to make a selection from the options listed in the given list. The it should get input from the user. Place " >" in front of user input. if the user doesn't input one of the given choices, then the program should repeatedly ask the user to pick from the list. Finally, the function should return the word...
Please create a Python program that can convert a text string to an encrypted message and...
Please create a Python program that can convert a text string to an encrypted message and convert the encrypted message back to the original message. Read a string message from your keyboard. Print the input string. Convert this message into an encrypted message by using a list element substitution. Print your encrypted message. Convert this encrypted message back to the original message by using a list element substitution. Print your original message. Important: please use a dictionary data type and...
In python write a function whose input is a string. This function determines the data type...
In python write a function whose input is a string. This function determines the data type of the input string. The data types can be a float, int, or string. Most pass the following assertions: assert determine_data_type('1.2') == float assert determine_data_type('4') == int assert determine_data_type('EAS503') == str
Write a python function to fulfill the requirements. The function accepts a string, a current state,...
Write a python function to fulfill the requirements. The function accepts a string, a current state, edges’ information, and an accepting state. The output of the function is a boolean value verifying if the string can pass the finite state machine or not.             ### Finite State Machine Simulator in Python ### Provide s1 and s2 that are both accepted, but s1 != s2. s1 = "bdf" s2 = "bdgbdf" edges = {(1,'a') : 2,                (1,'b') : 3,       ...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT