30 Days of Python: Day 26 Cryptoquip

I’m making a small project every day in python for the next 30 days (minus some vacation days). I’m hoping to learn many new packages and  make a wide variety of projects, including games, computer tools, machine learning, and maybe some science. It should be a good variety and I think it will be a lot of fun.

Day 26: Cryptoquip

For today’s project, I made a cryptoquip game. This is my favorite newspaper puzzle where the goal is to decode a witty saying that’s been encrypted with a substitution cipher. Spaces and punctuation are left in tack so it’s all about guessing which letters are which by looking for letters that might be by themselves (a, I) or double letters (often e, l, etc.). It’s a fun puzzle to play. Here’s a screenshot of one that’s nearly solved:

Einstein Quote

The encryption method is very easy to implement. The key is a dictionary with a random shuffle of a ciphertext alphabet mapped to the plaintext alphabet. The ciphertext (the encoded message) uses all caps, while the plaintext uses lower case. A simple list comprehension can do the substitution:

def encrypt_substitute(message, key):
    '''Encrypts the message with a substitution cipher'''
    return ''.join([key[m] if m in key else m for m in message])

For the guessing portion, the player moves the cursor around with the arrows and can work in either the message or on the side in the key. The working key is initialized with all underscores for each ciphertext letter. The same encryption method does the encryption with the reversed key. I wanted to add the ability click on the letter you want to change but I ran out of time. Perhaps I’ll come back and add that after the 30 days are up, which isgetting quite close.

For those who are interested here’s my github repo for the games project: https://github.com/robb07/python_games




2 thoughts on “30 Days of Python: Day 26 Cryptoquip

  1. I really like your 30 days of Python idea. Thanks for putting it together.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s