Question: Bonus: Recursive Encryption (3 points) Privacy has been a major talking point amongst many tech giants as of the past 2 years. Let's be creative

 Bonus: Recursive Encryption (3 points) Privacy has been a major talking

Bonus: Recursive Encryption (3 points) Privacy has been a major talking point amongst many tech giants as of the past 2 years. Let's be creative and find a way to encrypt our messages to send to one another! Define a function encrypt which takes 3 arguments msg - a non-empty string message shift - a non-negative integer func - a lambda function that takes one integer argument and returns an integer. For the math lovers (which means all of you) the type definition looks like this: Int Int The secret sauce to this encryption method is that it will shift every character by some integer amount shift. For example 'h' shifted 5 characters is 'm'. When shift is positive value, the shifted char will move in the (right) direction based on nominal value. (Consult Ascii chart for more info: http://www.asciitable.com/) Therefore, we will go through every character c in the string and modify each by increasing the ordinalominal value by shift creating a new character c' (pronounced C-prime or /s/yah/prm/). Here's the catch, the shift for the next character will always change, as dictated by the lambda function func. The lambda function should receive as argument the ordinal value of c'( ord(c')) from that recursive call and return you a new shift integer value... (Oh yea, do this recursively; you'll thank me later.) But in the iterative sense, func supplies you with the next shift value for the next proceeding character. HINT: With a recursive solution, this can be as little as 2 lines of concise code, first defining a base case (string of length 1), and then computing the solution in terms of its own smaller subproblems (the remainder of string). WINK: Use ord and chr built ins. #Your code here def encrypt(msg, shift, func): return print("Are my sample test cases correct?") print("#1", encrypt("hello",1, lambda x: (x + 1) % 10 ) == "iktsu") print("#2", encrypt("covfefe", 13, lambda x: x % 13 if x % 2 == 0 else x x 3) == "pwxiehe") print("#3", encrypt("precious", 12, lambda x: x + 1) == "Trgo")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!