In: Computer Science
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.
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