{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "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*, which you can read up more about [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 function that given a string and a shift, will produce the encrypted string for that shift. Note that the same function 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", " gwc uivioml bw nqvl bpm zqopb apqnb\n", " \n", "Hint: 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 (``[4]``) to convert from numbers to letters, and the ``index`` method to convert from letters to numbers." ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Solution" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "# your solution here\n" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }