+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from support.utilities import *\n",
+ "from support.language_models import *\n",
+ "from support.norms import *\n",
+ "from cipher.keyword_cipher import *"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def keyword_encipher_p(message, keyword, wrap_alphabet=KeywordWrapAlphabet.from_a):\n",
+ " cipher_alphabet = keyword_cipher_alphabet_of(keyword, wrap_alphabet)\n",
+ " cipher_translation = {p: c for p, c in zip(string.ascii_lowercase, cipher_alphabet)}\n",
+ " return cat(keyword_encipher_letter(letter, cipher_translation) for letter in message)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def keyword_decipher_p(message, keyword, wrap_alphabet=KeywordWrapAlphabet.from_a):\n",
+ " cipher_alphabet = keyword_cipher_alphabet_of(keyword, wrap_alphabet)\n",
+ " plaintext_translation = {c: p for p, c in zip(string.ascii_lowercase, cipher_alphabet)}\n",
+ " return cat(keyword_encipher_letter(letter, plaintext_translation) for letter in message)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def keyword_encipher_letter(letter, cipher_translation):\n",
+ " if letter in cipher_translation:\n",
+ " return cipher_translation[letter]\n",
+ " else:\n",
+ " return letter"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'qopq hoppkdo'"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "keyword_encipher('test message', 'keyword')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'qopq hoppkdo'"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "keyword_encipher_p('test message', 'keyword')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'test message'"
+ ]
+ },
+ "execution_count": 10,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "keyword_decipher_p('qopq hoppkdo', 'keyword')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "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.4.5"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}