<jupyter_start><jupyter_text>Assignment 02 Today's exercises have to be done with help of the python **standard library** alone! **No external module can be used**.:::{tip}Can you remember what the "standard library" is? [Here](https://docs.python.org/3/library/) is a list of all the modules and built-ins it provides: so quite a lot!:::  Exercise 02-01: cryptography for Roman Emperors A very simple encryption technique is called the [Caesar cipher](http://en.wikipedia.org/wiki/Caesar_cipher). The basic idea is that each letter is replaced by a letter that is a certain number of letters away, so for example if the shift was 2, then A would become C, B would become D, and Z will become B.**A. Write a function that given a string and a shift, will produce the encrypted string for that shift**. The rules are:- you should accept lowercase and uppercase letters, and return letters of the same case- spaces or other punctuation characters should not be changed.There are several ways to reach this result. Just pick the one which makes more sense to you. Then, decrypt the following message, which was encrypted with a shift of 13:        Pbatenghyngvbaf, lbh unir fhpprrqrq va qrpelcgvat gur fgevat.    **B. Now write a decoding script** `caesar.py` which, when run in the command line, prints the decoded phrase after asking the user to enter a phrase and a shift with which it was encrypted. Test your script on the sentence above. :::{tip}Make use of python's [input()](https://docs.python.org/3/library/functions.htmlinput) function:::**C. Now try to decrypt this sentence, for which the shift is unknown**:        Gwc uivioml bw nqvl bpm zqopb apqnb.    One way to solve this problem involves human decision, but another way can be fully automated (and implies more work). Pick the one you want! You can also add the decryption option to your script if you want.  Exercise 02-02: the substitution cipher Since we managed to crack the code above so easily, maybe we should use a better cryptographic algorithm from now on. The Caesar cipher is a special case of the more general [substitution cipher](https://en.wikipedia.org/wiki/Substitution_cipher). In this cipher, any new combined alphabet (or sequence of bits, characters, numbers...) can be used in place of the regular alphabet.To simplify things a bit, we will use python's `random` module and in particular it's [shuffle](https://docs.python.org/3/library/random.htmlrandom.shuffle) function to do the job. To generate a random (but predictable) substitution table we can use the mechanism of "seeds", which can be seen as a secret key that you'll have to (privately) give to your forbidden lover for him/her to decipher your message. This works as following:<jupyter_code>alphabet = 'abcdefghijklmnopqrstuvwxyz'
seed = 42  # the secret key known by both parties 

import random
random.seed(seed)

new_alphabet = list(alphabet)
random.shuffle(new_alphabet)
print(new_alphabet)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0695330870003359, 'fraction_numerical': 0.006046355391333557, 'mean_word_length': 4.629489603024575, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '156767', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 817, 'n_tokens_neox': 769, 'n_words': 430, 'path': 'book/week_02/Assignment-02.ipynb', 'repo_name': 'fmaussion/scientific_programming', 'size': '2977'}