Skip to content

Instantly share code, notes, and snippets.

@ladyrassilon
Created May 30, 2024 09:16
Show Gist options
  • Save ladyrassilon/0395d8c70af11ed66368e308b3f96e19 to your computer and use it in GitHub Desktop.
Save ladyrassilon/0395d8c70af11ed66368e308b3f96e19 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "5387388b-0842-4b3b-8fa2-855c69424d7c",
"metadata": {},
"outputs": [],
"source": [
"message = \"xf dpvme ofwfs xpsl uibu pvu\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ee589d69-5024-40d7-a0da-26edc370d814",
"metadata": {},
"outputs": [],
"source": [
"from collections import deque"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b05978ec-ae16-476f-8ac5-3061b23563bc",
"metadata": {},
"outputs": [],
"source": [
"import string"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "4376ad91-f126-4337-9dd1-5034386c4820",
"metadata": {},
"outputs": [],
"source": [
"map_to = list(string.ascii_lowercase)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9a78a286-3b82-43d2-8c78-160f28ca9c86",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"deque(['y',\n",
" 'z',\n",
" 'a',\n",
" 'b',\n",
" 'c',\n",
" 'd',\n",
" 'e',\n",
" 'f',\n",
" 'g',\n",
" 'h',\n",
" 'i',\n",
" 'j',\n",
" 'k',\n",
" 'l',\n",
" 'm',\n",
" 'n',\n",
" 'o',\n",
" 'p',\n",
" 'q',\n",
" 'r',\n",
" 's',\n",
" 't',\n",
" 'u',\n",
" 'v',\n",
" 'w',\n",
" 'x'])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"map_from = deque(map_to.copy())\n",
"map_from.rotate(2)\n",
"map_from"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "fa954f19-bd74-4a6b-a7ae-dc31d8ad57ee",
"metadata": {},
"outputs": [],
"source": [
"potential_decode = dict(zip(map_from,map_to))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "47b0257d-ed77-46d4-a058-f57607a94508",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"zh frxog qhyhu zrun wkdw rxw\n"
]
}
],
"source": [
"decoded = []\n",
"for letter in message:\n",
" if letter in string.ascii_lowercase:\n",
" decoded.append(potential_decode[letter])\n",
" else:\n",
" decoded.append(letter)\n",
"print(\"\".join(decoded))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "d2aaa8f8-c493-45fd-9916-d970f68141ff",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"yg eqwnf pgxgt yqtm vjcv qwv\n",
"zh frxog qhyhu zrun wkdw rxw\n",
"ai gsyph riziv asvo xlex syx\n",
"bj htzqi sjajw btwp ymfy tzy\n",
"ck iuarj tkbkx cuxq zngz uaz\n",
"dl jvbsk ulcly dvyr aoha vba\n",
"em kwctl vmdmz ewzs bpib wcb\n",
"fn lxdum wnena fxat cqjc xdc\n",
"go myevn xofob gybu drkd yed\n",
"hp nzfwo ypgpc hzcv esle zfe\n",
"iq oagxp zqhqd iadw ftmf agf\n",
"jr pbhyq arire jbex gung bhg\n",
"ks qcizr bsjsf kcfy hvoh cih\n",
"lt rdjas ctktg ldgz iwpi dji\n",
"mu sekbt duluh meha jxqj ekj\n",
"nv tflcu evmvi nfib kyrk flk\n",
"ow ugmdv fwnwj ogjc lzsl gml\n",
"px vhnew gxoxk phkd matm hnm\n",
"qy wiofx hypyl qile nbun ion\n",
"rz xjpgy izqzm rjmf ocvo jpo\n",
"sa ykqhz jaran skng pdwp kqp\n",
"tb zlria kbsbo tloh qexq lrq\n",
"uc amsjb lctcp umpi rfyr msr\n",
"vd bntkc mdudq vnqj sgzs nts\n",
"we could never work that out\n"
]
}
],
"source": [
"for i in range (1, 26):\n",
" map_from = deque(map_to.copy())\n",
" map_from.rotate(i)\n",
" potential_decode = dict(zip(map_from,map_to))\n",
" decoded = []\n",
" for letter in message:\n",
" if letter in string.ascii_lowercase:\n",
" decoded.append(potential_decode[letter])\n",
" else:\n",
" decoded.append(letter)\n",
" print(\"\".join(decoded))\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ac043960-403e-40f8-9d86-d02e17a77423",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment