SlideShare une entreprise Scribd logo
1  sur  2
Télécharger pour lire hors ligne
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
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/

Contenu connexe

Similaire à Python Cryptography

Avoid adding a new library to the project
Avoid adding a new library to the projectAvoid adding a new library to the project
Avoid adding a new library to the projectPVS-Studio
 
F# for startups v2
F# for startups v2F# for startups v2
F# for startups v2joelgrus
 
Learning through answering
Learning through answeringLearning through answering
Learning through answeringEran Zimbler
 
Natural Language Processing with Neo4j
Natural Language Processing with Neo4jNatural Language Processing with Neo4j
Natural Language Processing with Neo4jKenny Bastani
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.pptRehnawilson1
 
Celebrating 30-th anniversary of the first C++ compiler: let's find bugs in it.
Celebrating 30-th anniversary of the first C++ compiler: let's find bugs in it.Celebrating 30-th anniversary of the first C++ compiler: let's find bugs in it.
Celebrating 30-th anniversary of the first C++ compiler: let's find bugs in it.PVS-Studio
 
Cucumbers Have Layers - RubyConf 2015
Cucumbers Have Layers - RubyConf 2015Cucumbers Have Layers - RubyConf 2015
Cucumbers Have Layers - RubyConf 2015Sam Livingston-Gray
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic RevisitedAdam Keys
 
Python presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, BiharPython presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, BiharUttamKumar617567
 
Scottish Ruby Conference 2014
Scottish Ruby Conference  2014Scottish Ruby Conference  2014
Scottish Ruby Conference 2014michaelag1971
 
Effective text editing with vim
Effective text editing with vimEffective text editing with vim
Effective text editing with vimxprayc
 

Similaire à Python Cryptography (20)

Handson Python
Handson PythonHandson Python
Handson Python
 
Avoid adding a new library to the project
Avoid adding a new library to the projectAvoid adding a new library to the project
Avoid adding a new library to the project
 
F# for startups v2
F# for startups v2F# for startups v2
F# for startups v2
 
Learning through answering
Learning through answeringLearning through answering
Learning through answering
 
Natural Language Processing with Neo4j
Natural Language Processing with Neo4jNatural Language Processing with Neo4j
Natural Language Processing with Neo4j
 
Graphql
GraphqlGraphql
Graphql
 
Apex for humans
Apex for humansApex for humans
Apex for humans
 
core python.pdf
core python.pdfcore python.pdf
core python.pdf
 
Tensorflow go
Tensorflow goTensorflow go
Tensorflow go
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.ppt
 
Python3handson
Python3handsonPython3handson
Python3handson
 
Celebrating 30-th anniversary of the first C++ compiler: let's find bugs in it.
Celebrating 30-th anniversary of the first C++ compiler: let's find bugs in it.Celebrating 30-th anniversary of the first C++ compiler: let's find bugs in it.
Celebrating 30-th anniversary of the first C++ compiler: let's find bugs in it.
 
Cucumbers Have Layers - RubyConf 2015
Cucumbers Have Layers - RubyConf 2015Cucumbers Have Layers - RubyConf 2015
Cucumbers Have Layers - RubyConf 2015
 
venv and pip.pdf
venv and pip.pdfvenv and pip.pdf
venv and pip.pdf
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic Revisited
 
Python presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, BiharPython presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, Bihar
 
Scottish Ruby Conference 2014
Scottish Ruby Conference  2014Scottish Ruby Conference  2014
Scottish Ruby Conference 2014
 
Effective text editing with vim
Effective text editing with vimEffective text editing with vim
Effective text editing with vim
 
Taming Text
Taming TextTaming Text
Taming Text
 
interviewbit.pdf
interviewbit.pdfinterviewbit.pdf
interviewbit.pdf
 

Python Cryptography

  • 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/