Question
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
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 python 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:
IntInt
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 ordinal/nominal 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started