Skip to content

Instantly share code, notes, and snippets.

@Jamesalambert
Last active March 5, 2021 14:22
Show Gist options
  • Save Jamesalambert/67d54071d5d11846329b7b0f6f70710c to your computer and use it in GitHub Desktop.
Save Jamesalambert/67d54071d5d11846329b7b0f6f70710c to your computer and use it in GitHub Desktop.
Cipher Solver.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Cipher Solver.ipynb",
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/Jamesalambert/67d54071d5d11846329b7b0f6f70710c/cipher-tools-end.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "qpISfiF9enhx"
},
"source": [
"import string, random\n",
"\n",
"sample_text = \"\"\"\n",
"put any block of text here so you can guess letter frequencies.\n",
"\"\"\".lower()\n",
"\n",
"ciphertext = \"\"\"\n",
"paste in your ciphertext here.\n",
"\"\"\"\n",
"\n",
"plaintext = sample_text\n",
"\n",
"\n",
"alphabet = string.ascii_lowercase"
],
"execution_count": 8,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "o4XHEk_nbKIb",
"outputId": "ebd4471f-e362-4765-b504-4bedfa7a6e7a"
},
"source": [
"def letterCount(text):\n",
" for letter in alphabet:\n",
" number_of_times = text.count(letter)\n",
" print(letter, number_of_times, number_of_times * \"|\" )\n",
"\n",
"letterCount(sample_text)\n",
"#letterCount(ciphertext)"
],
"execution_count": 9,
"outputs": [
{
"output_type": "stream",
"text": [
"a 79 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n",
"b 12 ||||||||||||\n",
"c 20 ||||||||||||||||||||\n",
"d 32 ||||||||||||||||||||||||||||||||\n",
"e 109 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n",
"f 13 |||||||||||||\n",
"g 17 |||||||||||||||||\n",
"h 48 ||||||||||||||||||||||||||||||||||||||||||||||||\n",
"i 62 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n",
"j 0 \n",
"k 4 ||||\n",
"l 30 ||||||||||||||||||||||||||||||\n",
"m 18 ||||||||||||||||||\n",
"n 61 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n",
"o 63 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n",
"p 5 |||||\n",
"q 0 \n",
"r 54 ||||||||||||||||||||||||||||||||||||||||||||||||||||||\n",
"s 42 ||||||||||||||||||||||||||||||||||||||||||\n",
"t 88 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n",
"u 20 ||||||||||||||||||||\n",
"v 9 |||||||||\n",
"w 22 ||||||||||||||||||||||\n",
"x 0 \n",
"y 15 |||||||||||||||\n",
"z 0 \n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "dd2Z8K-Vck1P",
"outputId": "10862912-ff35-44c4-9820-b5f2ae74b483"
},
"source": [
"# abcdefghijklmnopqrstuvwxyz\n",
"guess_alphabet = \"xyzabcdefghijklmnopqrstuvw\" #put your guess alphabet here\n",
"\n",
"def decode(ciphertext, guess_key):\n",
"\n",
" decoder_wheel = str.maketrans(alphabet, guess_key)\n",
"\n",
" for line in ciphertext.split(\"\\n\"):\n",
" print(line)\n",
" print(line.translate(decoder_wheel))\n",
"\n",
"decode(ciphertext, guess_alphabet)"
],
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"text": [
"\n",
"\n",
"paste in your ciphertext here\n",
"mxpqb fk vlro zfmeboqbuq ebob\n",
"\n",
"\n"
],
"name": "stdout"
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment