- Use only commands, functions, datatypes from Python Part 1 class.
- You are free to use whatever resource to learn about the subject of task. Please avoid plagiarism - the task is for you to learn, not for us to evaluate you.
- Refrain from using pre-existing libraries/functions/other structures. Both problems are completely doable using the content for Python Part 1 class.
- Both the problems are mandatory.
Lagrange interpolation is a polynomial interpolation method which uses polynomials known as Lagrange Polynomials. This method works on a set of uniqe points, and results in a polynomial with degree one less than the number of data points - which passess through all the data points.
Your task is to write a function lagrange_polynomial() which takes in a list
of data points (which are two element lists themselves), and another argument,
and returns the value of the interpolating polynomial at the given argument.
lagrange_polynomial(datalist, xvalue)
# datalist is a list of points, like [[1,2],[4,9],[13,27]] etc.
# xvalue is value at which we need the interpolating polynomial to be evaluated.An example workflow would be:
yval = lagrange_polynomial([[8, 6], [1, 3], [3, 8]], 4)
print(yval)Output:
9.257142857142858
Cipher is an element of cryptography - which is essentially a set of rules to
encrypt (and decrypt) a message (encrypted message). One example of such cipher
is the ROT13
cipher, which is: shift each alphabet of the message forward by 13 counts. By
this rule a becomes n, b becomes o and so on:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
The cipher we discuss will have the number of shifts as a variable, rather than sticking to 13 like ROT-13 does (hence the name ROT-N).
Another simple example of cipher is the Atbash cipher, where the letters of the
alphabet are reversed. The goal of this problem is to create a two functions
inv_rotn_encrypt() and inv_rotn_decrypt() - one for encrypting, one for
decrypting. The arguments for these functions is as follows:
inv_rotn_encrypt(message, shift)
# message is the message to be encrypted
# shift is the number of letters to shift
inv_rotn_decrypt(secret, shift)
# secret is the encrypted message to be decrypted to obtain original message
# shift is the number of shifts used to encrypt the original messageEncrypting process:
- Shift the letters of the message by the number specified by
shiftargument. (note that the shift argument should always be an integer, as the concept of fractional shift is absurd). - Reverse the order of the letters obtained from previous step.
- Return the encrypted message obtained thus.
Decrypting process:
- Reverse the order of characters in the given encrypted message.
- Shift backwards the string obtained from previous step by the specified
shiftnumber. - Return the decrypted message obtained thus.
An example workflow would be:
message = 'bobody'
print("Message: ", message)
secret = inv_rotn_encrypt(message, 17)
print("Encrypted message: ", secret)
message_again = inv_rotn_decrypt(secret, 17)
print("Decrypted message: ", message_again)Output:
Message: bobody
Encrypted message: pufsfs
Decrypted message: bobody
- Fork this repository.
- Make a copy of
template.ipynbinsidesubmissionsdirectory with your roll number e.g.ph19b003.ipynb(in lowercase). - Add responses (1 function in Problem 1, and 2 functions in Problem 2) in the jupyter notebook you copied.
- Commit the changes, push to your account.
- Create a pull request with title format
rollnumber_name. It should be in all lowercase, and replace spaces in name with-. - And that's it!