The student implemented a columnar transposition cipher and dictionary attack in Python to decrypt a ciphertext. They used online resources like Invent With Python and Pycipher library to build the cipher. The dictionary attack program decrypted the text by shifting letters and checking if words exist in a dictionary file. It took 15 words or more to identify a potential decryption. The student learned about cryptography and improved their Python skills through this challenging homework assignment.
1. Homework 3 Comp 429 Dragos Guta
Dec 1st, 2014
Problem 1. You intercepted a single ciphertext. Decipher it as much as you can. To receive
full or partial credit you must show all your work. Attach any code you have implemented or any
code you have found anywhere (but make sure that you include citation of sources you used as well).
DRPWPWXHDRDKDUBKIHQVQRIKPGWOVOESWPKPVOBBDVVVDXSURWRLUEBKOLVHIHBKHLHBLNDQRFLOQ
1 Introduction
The homework assignment itself was difficult in my opinion. I wasn’t sure how to approach it at
first and it wasn’t until we received more clues in class that I was fully able to understand what I
needed to do.
I started off by looking at the different ciphers and reading about them on Wikipedia. I real-
ized that without programming or writing some code, the chances of deciphering the string would
be near 0. I also tried my hand at some frequency analysis but I hit a roadblock and figured that I
would just brute force it. I chose Python as my programming language because I saw it as a good
way to learn python and because I also knew there was great support in Python for cryptography.
2 Method of Attack
One of the sources that I used early in the beginning was Invent With Python1. The website has a
large amount of information in terms of hacking and cryptography. I figured in the beginning that
this might be a Vigenere Cipher and that I might get lucky with their own implementation in terms
of encrypting and decrypting. Obviously I was wrong so I began to build my own columnar transpo-
sition. Again, Invent With Python had plenty of resources and their own implementation, and this
2. Comp 429 Homework 3: Dragos Guta 2
helped me a great deal, especially since I did not have as much experience in Python as I would like.
After a good amount of Stack Overflow2 threads, I was able to build my own columnar trans-
position encrypt but I hit a roadblock on the decrypt. It was then that I found Pycipher3. This
library had both the columnar transposition and the simple substitution built in, as well as a good
amount of other ciphers.
The rest of the work included connecting everything together. I used a standard dictionary at-
tack, implementing a dictionary.txt file containing 45,000 words and then passed each one into
the ’ColTrans’ function. The two hard parts were detecting the English words once the string had
been decrypted and implementing the simple substitution correctly. In terms of finding the words,
I was thinking of implementing a ’peek’ algorithm in which the whole string is searched, in a letter
by letter fashion, and then checked. So, it would work along the lines of: Is the first letter a word?
No, add another letter, and so on. This proved to be too time consuming so I opted to just create
all possible words from the string, check that they exist in the dictionary.txt file, and then if the
string contains more than 15 possible words, it might be decrypted, and the program should ask
for user input. I chose 15 arbitrarily, I tinkered with other values but, for example, with greater
than 5 there were too many possibilities.
The substitution cipher was tricky mainly because I didn’t know how to properly shift the let-
ters in Python. Along with countless Stack Overflow threads, I used an online tool4 and passed
the substitution manually. I got lucky and decrypted it on the third try or shift. After which I was
able to implement it properly, where the shifting was done automatically starting from 1 to 26 for
every word in the dictionary.
3 Conclusion
As far as final thoughts go, this homework assignment was more like a project on its own. I learned
a great deal about Python and I’m especially glad that I used it in conjunction with Pycipher since
it simplified everything. I thought the decrypted quote was more profound also because of the
amount of effort poured into cracking this string. On a final note, I was impressed with the overall
time it took for the program to find the decryption. I suppose this is due in part to the fact that
it does not really perform any calculations. If the decryption key was not a dictionary word such
as ’kodak’ then this method of attack would not work and therefore, decrypting the string would
be much, much harder.
4 Sources
1. http://inventwithpython.com/hacking/chapters/
2. http://stackoverflow.com/questions/tagged/python
3. http://pycipher.readthedocs.org/en/latest/
4. http://www.xarg.org/tools/caesar-cipher/