16 "execution_count": 40,
22 "def sanitised(text):\n",
23 " return ''.join(letter.lower() for letter in text if letter in string.ascii_letters)"
28 "execution_count": 41,
36 "'thequickbrownfoxjumpedoverthelzydoga'"
39 "execution_count": 41,
41 "output_type": "execute_result"
45 "sanitised('The quick brown fox! jumped OVER the l\\a!z%y* dog....a')"
56 "def encipher_letter(previous, current):\n",
57 " new = (ord(previous) + ord(current) - 2 * ord('a')) % 26\n",
58 " return chr(new + ord('a'))"
63 "execution_count": 15,
69 "def decipher_letter(previous, current):\n",
70 " new = (ord(current) - ord(previous) - 2 * ord('a')) % 26\n",
71 " return chr(new + ord('a'))"
89 "output_type": "execute_result"
93 "encipher_letter('a', 'a')"
106 "'abcdefghijklmnopqrstuvwxyz'"
109 "execution_count": 6,
111 "output_type": "execute_result"
115 "''.join(encipher_letter('a', l) for l in string.ascii_lowercase)"
120 "execution_count": 7,
128 "'bcdefghijklmnopqrstuvwxyza'"
131 "execution_count": 7,
133 "output_type": "execute_result"
137 "''.join(encipher_letter('b', l) for l in string.ascii_lowercase)"
142 "execution_count": 17,
150 "'abcdefghijklmnopqrstuvwxyz'"
153 "execution_count": 17,
155 "output_type": "execute_result"
159 "''.join(decipher_letter('a', l) for l in string.ascii_lowercase)"
164 "execution_count": 18,
175 "execution_count": 18,
177 "output_type": "execute_result"
181 "decipher_letter('a', 'b')"
185 "cell_type": "markdown",
188 "e = (p + c) % 26\n",
194 "execution_count": 20,
202 "'abcdefghijklmnopqrstuvwxyzbcdefghijklmnopqrstuvwxyzacdefghijklmnopqrstuvwxyzabdefghijklmnopqrstuvwxyzabcefghijklmnopqrstuvwxyzabcdfghijklmnopqrstuvwxyzabcdeghijklmnopqrstuvwxyzabcdefhijklmnopqrstuvwxyzabcdefgijklmnopqrstuvwxyzabcdefghjklmnopqrstuvwxyzabcdefghiklmnopqrstuvwxyzabcdefghijlmnopqrstuvwxyzabcdefghijkmnopqrstuvwxyzabcdefghijklnopqrstuvwxyzabcdefghijklmopqrstuvwxyzabcdefghijklmnpqrstuvwxyzabcdefghijklmnoqrstuvwxyzabcdefghijklmnoprstuvwxyzabcdefghijklmnopqstuvwxyzabcdefghijklmnopqrtuvwxyzabcdefghijklmnopqrsuvwxyzabcdefghijklmnopqrstvwxyzabcdefghijklmnopqrstuwxyzabcdefghijklmnopqrstuvxyzabcdefghijklmnopqrstuvwyzabcdefghijklmnopqrstuvwxzabcdefghijklmnopqrstuvwxy'"
205 "execution_count": 20,
207 "output_type": "execute_result"
211 "''.join(encipher_letter(k, l) for l in string.ascii_lowercase for k in string.ascii_lowercase)"
216 "execution_count": 21,
224 "[('a', 'a', 'a'),\n",
225 " ('b', 'a', 'b'),\n",
226 " ('c', 'a', 'c'),\n",
227 " ('d', 'a', 'd'),\n",
228 " ('e', 'a', 'e'),\n",
229 " ('f', 'a', 'f'),\n",
230 " ('g', 'a', 'g'),\n",
231 " ('h', 'a', 'h'),\n",
232 " ('i', 'a', 'i'),\n",
236 "execution_count": 21,
238 "output_type": "execute_result"
242 "encrypted = [(k, l, encipher_letter(k, l)) for l in string.ascii_lowercase for k in string.ascii_lowercase]\n",
248 "execution_count": 22,
259 "execution_count": 22,
261 "output_type": "execute_result"
265 "all(l == decipher_letter(k, e) for k, l, e in encrypted)"
270 "execution_count": 55,
276 "def encipher_message(plaintext, key='a'):\n",
277 " ciphertext = ''\n",
279 " for letter in plaintext:\n",
280 " cipherletter = encipher_letter(previous, letter)\n",
281 " ciphertext += cipherletter\n",
282 " previous = cipherletter\n",
283 " # previous = letter\n",
289 "execution_count": 56,
300 "execution_count": 56,
302 "output_type": "execute_result"
306 "encipher_message('hello')"
311 "execution_count": 57,
322 "execution_count": 57,
324 "output_type": "execute_result"
328 "encipher_message('hello', 'q')"
333 "execution_count": 54,
339 "def decipher_message(ciphertext, key='a'):\n",
342 " for letter in ciphertext:\n",
343 " plainletter = decipher_letter(previous, letter)\n",
344 " plaintext += plainletter\n",
345 " previous = letter\n",
346 " # previous = plainletter\n",
352 "execution_count": 58,
363 "execution_count": 58,
365 "output_type": "execute_result"
369 "decipher_message('hlwhv')"
374 "execution_count": 59,
385 "execution_count": 59,
387 "output_type": "execute_result"
391 "decipher_message('xbmxl')"
396 "execution_count": 60,
407 "execution_count": 60,
409 "output_type": "execute_result"
413 "decipher_message('xbmxl', 'q')"
418 "execution_count": 61,
426 "'hlwhvjxlznbpdrfthvjxlznbpd'"
429 "execution_count": 61,
431 "output_type": "execute_result"
435 "encipher_message('helloooooooooooooooooooooo')"
440 "execution_count": 62,
448 "'helloooooooooooooooooooooo'"
451 "execution_count": 62,
453 "output_type": "execute_result"
457 "decipher_message('hlwhvjxlznbpdrfthvjxlznbpd')"
462 "execution_count": null,
472 "display_name": "Python 3",
473 "language": "python",
481 "file_extension": ".py",
482 "mimetype": "text/x-python",
484 "nbconvert_exporter": "python",
485 "pygments_lexer": "ipython3",