Python-Kurs - iPython-Dingsis
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Practice Problem - Cryptography"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Cryptography is the study of how to make messages secret or how to read secret messages. A very simple encryption technique is called the *Caesar cipher* -- more information on it can be found [here](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, etc. (and Z will become B).\n",
|
||||
"\n",
|
||||
"Write a piece of code that given a string and a shift, will produce the encrypted string for that shift. Note that the same routine can be used to decrypt a message, by passing it a negative shift. \n",
|
||||
"\n",
|
||||
"The rules are: you should only accept and return lowercase letters, and spaces should not be changed.\n",
|
||||
"\n",
|
||||
"Then, decrypt the following message, which was encrypted with a shift of 13:\n",
|
||||
" \n",
|
||||
" pbatenghyngvbaf lbh unir fhpprrqrq va qrpelcgvat gur fgevat \n",
|
||||
" \n",
|
||||
"Now if you are up for a challenge, try and decrypt this **and** find the shift:\n",
|
||||
" \n",
|
||||
" wxkxmh ngynlcb cqn byjwrbq rwzdrbrcrxw\n",
|
||||
" \n",
|
||||
"**Note**: there are several ways you can convert between letters and numbers. One is to use the built-in functions ``chr`` and ``ord`` (and remember you can find out more about a function by using ``?`` in IPython). Another is to set up the alphabet in a string and use item access (``[3]``) to convert from numbers to letters, and the ``index`` method to convert from letters to numbers."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Solution"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"\n",
|
||||
"# your solution here\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
Reference in New Issue
Block a user