As our lecturer in cryptography wanted us to break some ciphertext (password needed!) encrypted using the Vigenère cipher. As this cipher was invented in 1553, it is, of course, long broken. But I decided to implement the Kasiskitest and some simple frequency analysis as explained by Stinson in “Cryptography – Theory and Practice” using Java (I decided not to use C++, as the exercise sheet has other, more important questions and I didn’t want to spend waste my time debugging) as a small exercise for myself. You can fetch the code here.

How to use it:

wget http://dev.seb7.de/cVigenere.java
javac cVigenere.java
java cVigernere <ciphertext goes here>

The ciphertext is expected to be just one line, spaces are ignored. I copied the ciphertext we were to break into a file cryptoct (with spaces, but WITHOUT line breaks) and did java cVigenere $(cat cryptoct). If you have a long ciphertext, you should remove spaces as well (should be faster during initialization).

Now, what does the code do? Basically, we first do the Kasiskitest, which means we look for triplets (ok, I could use longer/shorter/variable patterns here, but triplets work just fine). Now we calculate the distance between each triplet and look for the Greatest common divisor, as this could probably be the keylength.

After we have the keylength, we can do usual frequency analysis, but only consider every key.length-th word. This means, we try to break the ciphertext like a normal Ceasar cipher, but instead of going through it only once, we do it key.length times.

If you really want to understand the code, take a look at the book, you can find it in the computer science library in Saarbrücken, but Kaiserslautern should have it as well ;-)

Leave a Reply