Please clearly outline all the steps taken to solve this
question. Please include a screenshot of your code if possible with
comments describing the function of each code. Please note that in
order for the code to be correct, it must give TRUE to all the test
cases that are included below each question. For each code that
works, I will give you a thumbs up. Thank you!
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:
msq -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:
The secret sauce to this encryption method is that it will shift every character by some integer amount shift.For
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 ordinal/nominal
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
func supplies you with the next shi ft 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
InI l: #Your code here def encrypt(msg, shift, func): return # YOUR CODE HERE raise NotImplementedError()
In [ ]:print("Are my sample test cases correct?") print("#1", encrypt("hello",1, lambda x: (x + 1) % 10 ) == "iktsu")
print("#3" encrypt("precious",12, lambda x: x + 1) == "|irg83o")
In []:
In []:
In [ ]: