Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add script to both en- and decode #1

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 176 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,176 @@
venv/
venv/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# VS CODE
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix
45 changes: 28 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
# Python Treasure Hunt

## Overview

We had a special lesson on encryption prepared for you today in the file `bacon_binary.py`, but somebody encrypted it! Luckily, the culprit left us some clues so we can restore it.

Before you begin, follow the instructions in the `Setup` section below, so you can run the code on your local machine.
Before you begin, follow the instructions in the `Setup` section below, so you can run the code on your local machine.

We'll walk through the clues together in the notebook `treasure_hunt.ipynb`. It will use our skills in indexing, Pandas, and regex.

We know that for each of the encrypted messages in the trail of clues, the culprit used the [Vigenere cipher](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher). The Vigenere cipher takes a string of letters as a key to encrypt a message, and can decrypt it using that same key. In today's mystery the Vigenere cipher is used three times, each with a different key and a different message.

# Start Here
The trail of clues starts in the file `today.py`. It's a poem by Frank O'Hara that has been broken into nested lists of possible keys. You'll have to use your list indexing skills.
- Get the 6th item in the 2nd list of the 2nd list of the 3rd list of the 2nd list of `possible_keys` in `today.py`.
- Uncomment line 9 of `decoded_messages.py` and pass the key as the second argument to `decrypt()`.
- This will decrypt the text in the file `regex_clue.py`, which will give you the second clue.
## Setup

Good luck!
1. Clone this repository on to your local computer:

### Setup
- Clone this repository on to your local computer:
```bash
git clone https://github.com/datastackacademy/treasure_hunt.git
```

`git clone https://github.com/datastackacademy/treasure_hunt.git`
1. Create a Python virtual environment & active it:

- Create a Python virtual environment:
```bash
cd treasure_hunt
python3 -m venv venv
source venv/bin/activate
```

`python3.7 -m venv venv`
1. Install the requirements in the `requirements.txt` file:

- Activate it:
```bash
pip install -r requirements.txt
```

`source venv/bin/activate`
1. Open the `treasure_hunt.ipynb` notebook and follow the instructions.

- Install the requirements in the `requirements.txt` file:

`pip install -r requirements.txt`
Good luck! 🍀🌠🤞

### References

The code in `vigenere.py` was closely adapted from Sweigart's book 'Cracking Codes with Python'.

- 'Today', by Frank O'Hara, 1950
- 'Cracking Codes with Python', by Al Sweigart, 2018
- 'Alice in Wonderland', by Lewis Carroll, 1865
- 'How to Make Anything Signify Anything', William Sherman for Cabinet Magazine, 2010
- 'How to Make Anything Signify Anything', William Sherman for Cabinet Magazine, 2010
78 changes: 39 additions & 39 deletions alice.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
rabbit_hole = "Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit \
with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the \
field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.\
In another moment down went Alice after it, never once considering how in the world she was to get out again.\
The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice \
had not a moment to think about stopping herself before she found herself falling down a very deep well.\
Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look \
about her and to wonder what was going to happen next. First, she tried to look down and make out what she was \
coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they \
were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. \
She took down a jar from one of the shelves as she passed; it was labelled 'ORANGE MARMALADE', but to her \
great disappointment it was empty: she did not like to drop the jar for fear of killing somebody underneath, \
so managed to put it into one of the cupboards as she fell past it.\
'Well!' thought Alice to herself, 'after such a fall as this, I shall think nothing of tumbling down stairs! \
How brave they’ll all think me at home! Why, I wouldn’t say anything about it, even if I fell off the top of \
the house!' (Which was very likely true.) Down, down, down. Would the fall never come to an end? 'I wonder how \
many miles I’ve fallen by this time?' she said aloud. 'I must be getting somewhere near the centre of the earth. \
Let me see: that would be four thousand miles down, I think—' (for, you see, Alice had learnt several things of \
this sort in her lessons in the schoolroom, and though this was not a very good opportunity for showing off her \
knowledge, as there was no one to listen to her, still it was good practice to say it over) '—yes, that’s about \
the right distance—but then I wonder what Latitude or Longitude I’ve got to?' (Alice had no idea what Latitude \
was, or Longitude either, but thought they were nice grand words to say.) Presently she began again. 'I wonder \
if I shall fall right through the earth! How funny it’ll seem to come out among the people that walk with their \
heads downward! The Antipathies, I think—' (she was rather glad there was no one listening, this time, as it \
didn’t sound at all the right word) '—but I shall have to ask them what the name of the country is, you know. \
Please, Ma’am, is this New Zealand or Australia?' (and she tried to curtsey as she spoke—fancy curtseying as \
you’re falling through the air! Do you think you could manage it?) 'And what an ignorant little girl she’ll \
think me for asking! No, it’ll never do to ask: perhaps I shall see it written up somewhere.' Down, down, down. \
There was nothing else to do, so Alice soon began talking again. 'Dinah’ll miss me very much to-night, I should \
think!' (Dinah was the cat.) 'I hope they’ll remember her saucer of milk at tea-time. Dinah my dear! I wish you \
were down here with me! There are no mice in the air, I’m afraid, but you might catch a bat, and that’s very \
like a mouse, you know. But do cats eat bats, I wonder?' And here Alice began to get rather sleepy, and went \
on saying to herself, in a dreamy sort of way, 'Do cats eat bats? Do cats eat bats?' and sometimes, 'Do bats \
eat cats?' for, you see, as she couldn’t answer either question, it didn’t much matter which way she put it. \
She felt that she was dozing off, and had just begun to dream that she was walking hand in hand with Dinah, and \
saying to her very earnestly, 'Now, Dinah, tell me the truth: did you ever eat a bat?' when suddenly, thump! \
thump! down she came upon a heap of sticks and dry leaves, and the fall was over. Alice was not a bit hurt, \
and she jumped up on to her feet in a moment: she looked up, but it was all dark overhead; before her was \
another long passage, and the White Rabbit was still in sight, hurrying down it."
rabbit_hole = """Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit
with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the
field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge
In another moment down went Alice after it, never once considering how in the world she was to get out again
The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice
had not a moment to think about stopping herself before she found herself falling down a very deep well
Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look
about her and to wonder what was going to happen next. First, she tried to look down and make out what she was
coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they
were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs.
She took down a jar from one of the shelves as she passed; it was labelled 'ORANGE MARMALADE', but to her
great disappointment it was empty: she did not like to drop the jar for fear of killing somebody underneath,
so managed to put it into one of the cupboards as she fell past it
'Well!' thought Alice to herself, 'after such a fall as this, I shall think nothing of tumbling down stairs!
How brave they’ll all think me at home! Why, I wouldn’t say anything about it, even if I fell off the top of
the house!' (Which was very likely true.) Down, down, down. Would the fall never come to an end? 'I wonder how
many miles I’ve fallen by this time?' she said aloud. 'I must be getting somewhere near the centre of the earth.
Let me see: that would be four thousand miles down, I think—' (for, you see, Alice had learnt several things of
this sort in her lessons in the schoolroom, and though this was not a very good opportunity for showing off her
knowledge, as there was no one to listen to her, still it was good practice to say it over) '—yes, that’s about
the right distance—but then I wonder what Latitude or Longitude I’ve got to?' (Alice had no idea what Latitude
was, or Longitude either, but thought they were nice grand words to say.) Presently she began again. 'I wonder
if I shall fall right through the earth! How funny it’ll seem to come out among the people that walk with their
heads downward! The Antipathies, I think—' (she was rather glad there was no one listening, this time, as it
didn’t sound at all the right word) '—but I shall have to ask them what the name of the country is, you know.
Please, Ma’am, is this New Zealand or Australia?' (and she tried to curtsey as she spoke—fancy curtseying as
you’re falling through the air! Do you think you could manage it?) 'And what an ignorant little girl she’ll
think me for asking! No, it’ll never do to ask: perhaps I shall see it written up somewhere.' Down, down, down.
There was nothing else to do, so Alice soon began talking again. 'Dinah’ll miss me very much to-night, I should
think!' (Dinah was the cat.) 'I hope they’ll remember her saucer of milk at tea-time. Dinah my dear! I wish you
were down here with me! There are no mice in the air, I’m afraid, but you might catch a bat, and that’s very
like a mouse, you know. But do cats eat bats, I wonder?' And here Alice began to get rather sleepy, and went
on saying to herself, in a dreamy sort of way, 'Do cats eat bats? Do cats eat bats?' and sometimes, 'Do bats
eat cats?' for, you see, as she couldn’t answer either question, it didn’t much matter which way she put it.
She felt that she was dozing off, and had just begun to dream that she was walking hand in hand with Dinah, and
saying to her very earnestly, 'Now, Dinah, tell me the truth: did you ever eat a bat?' when suddenly, thump!
thump! down she came upon a heap of sticks and dry leaves, and the fall was over. Alice was not a bit hurt,
and she jumped up on to her feet in a moment: she looked up, but it was all dark overhead; before her was
another long passage, and the White Rabbit was still in sight, hurrying down it."""
31 changes: 15 additions & 16 deletions bacon_binary.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
bacon_binary = "Txy Baeyd vipkhs ckzxyr yki wrgkjyd di jbe Enspubgdxun pyrfeokd Scr Ftkdwiu Bksin, \
yre cs cvii ctotctgn mctj sdpepdyhg vru mckodnihss gevrex. It'u dxy ptotycgciir qp cidgbd ASCII vipkhs cqnu, \
unf kd yatvo yxcwffe qp ineikdigtkfby, vru jrcmjccg yv wopmuulkxw hov tkmt c wumscqu vuv dxy fcmj nhcd jbe xsuqet \
si foquyhg cd q bifnuh mgciugg kj uln. Ix Bqwop'c scpjoh, yaer bytvoh if vru ulrrqvev melrgcfinfc ji a hsly-cjkhucvoh \
javduln, yrule gksb cjkhucvoh wap dqee qxu if vge zotwi (qhcd Bqwop mqflgn q-zotwi unf l-viroc, qhd yo miunn diw ekbf \
a dsj). Fir kxinapmu, nhg vuntgb 'B' cupu de 'uackr', unf dxy lgdjyr 'C' okfm tq 'kqubc'. Tru aepskm oh dxcs esfbet \
si nhcd jbe c-pelmu kdx b-hyhgs ekd una dmi dkcjcned sutgqeligc, bckg qhyy qb rfaeu fcxgvi cn cx ygaio, q loy yv \
nunsfm apn fytwxyus kx q zlqgulbgn, el tjo silqb ez tjbuudu sd u sjshn; a ekioan fyywgb miunnd'n nqdywe vrqn tjoo \
qeto biomsda av kd ynebojtgn cysukwy. Thg myjhgb sun cvii bg eiyd kx din-xsioan wuxic, vyee vru ponecy oh xeneu sd u \
sqxw. Tbeto'i yvgx q xoeecynvot yxcwffe qp q mckodniud qftgbyhg vru neozulavehy oh k vcsj rqvivkj mo vrqn tjo vcsjc' \
enonsjbsdydys vrqn afn q faaoh yaer oyat vyee vru lipqi if c dhyeyohy epmhspvot no toqx, mkmhiseyfcccvbs, 'hk weg'. \
bacon_binary = """Txy Baeyd vipkhs ckzxyr yki wrgkjyd di jbe Enspubgdxun pyrfeokd Scr Ftkdwiu Bksin,
yre cs cvii ctotctgn mctj sdpepdyhg vru mckodnihss gevrex. It'u dxy ptotycgciir qp cidgbd ASCII vipkhs cqnu,
unf kd yatvo yxcwffe qp ineikdigtkfby, vru jrcmjccg yv wopmuulkxw hov tkmt c wumscqu vuv dxy fcmj nhcd jbe xsuqet
si foquyhg cd q bifnuh mgciugg kj uln. Ix Bqwop'c scpjoh, yaer bytvoh if vru ulrrqvev melrgcfinfc ji a hsly-cjkhucvoh
javduln, yrule gksb cjkhucvoh wap dqee qxu if vge zotwi (qhcd Bqwop mqflgn q-zotwi unf l-viroc, qhd yo miunn diw ekbf
a dsj). Fir kxinapmu, nhg vuntgb 'B' cupu de 'uackr', unf dxy lgdjyr 'C' okfm tq 'kqubc'. Tru aepskm oh dxcs esfbet
si nhcd jbe c-pelmu kdx b-hyhgs ekd una dmi dkcjcned sutgqeligc, bckg qhyy qb rfaeu fcxgvi cn cx ygaio, q loy yv
nunsfm apn fytwxyus kx q zlqgulbgn, el tjo silqb ez tjbuudu sd u sjshn; a ekioan fyywgb miunnd'n nqdywe vrqn tjoo
qeto biomsda av kd ynebojtgn cysukwy. Thg myjhgb sun cvii bg eiyd kx din-xsioan wuxic, vyee vru ponecy oh xeneu sd u
sqxw. Tbeto'i yvgx q xoeecynvot yxcwffe qp q mckodniud qftgbyhg vru neozulavehy oh k vcsj rqvivkj mo vrqn tjo vcsjc'
enonsjbs (dydys vrqn afn q faaoh yaer oyat vyee vru lipqi if c dhye) yohy epmhspvot no toqx, mkmhiseyfcccvbs, 'hk weg'.
\
Frqw jbe ost-1800'm tq dxy 1940's vrule yki u fcn ji cqwr nhg zbuyu yv Sbamoijecbu, oskxw Bucqx'i wirrul tq veik hyh \
meebun mgciuggc el exstyneo jbav Ssh Flapmym Baeyd qau dxy rgkb uuvrel oh Srqeeuzuurg'c mirm. Ac qh ipduleudyhg \
jsinotssul ccyxe, qxu if vru zotocisv ktpoekjys qp jbiu mehsrshuca dxyoti, Dufic Bksin (py hylcdyin), jkfjepot no do q \
zrkodx oh Skcoen Myhme, kxlynvyh if Mqbiy cqnu."

Frqw jbe ost-1800'm tq dxy 1940's vrule yki u fcn ji cqwr nhg zbuyu yv Sbamoijecbu, oskxw Bucqx'i wirrul tq veik hyh
meebun mgciuggc el exstyneo jbav Ssh Flapmym Baeyd qau dxy rgkb uuvrel oh Srqeeuzuurg'c mirm. Ac qh ipduleudyhg
jsinotssul ccyxe, qxu if vru zotocisv ktpoekjys qp jbiu mehsrshuca dxyoti, Dufic Bksin (py hylcdyin), jkfjepot no do q
zrkodx oh Skcoen Myhme, kxlynvyh if Mqbiy cqnu."""
18 changes: 0 additions & 18 deletions decoded_messages.py

This file was deleted.

Loading