Cryptography: Implementing Vigenère's Polyalphabetic Cipher

Ah winter break, is there ever a better time to play with a readily breakable cipher? No, I don't mean Caesar cipher; I mean the next step up--Vigenère's polyalphabetic cipher.

Okay, so maybe it should be called Bellaso's polyalphabetic cipher, but I'm not here to argue credit vs naming vs popularity. Instead, I want to write a simple program to implement this simple cipher.

Vigenère's polyalphabetic cipher can be thought of as a modified Caesar cipher. Whereas Caesar would rotate the all the letters of a message by some offset (think rot13), Vigenère's uses a key word so the rotation for nearby letters can vary.

Imagine if the keyword was "loyalty", and I wanted to encode the message "the king is dead". For a Caesar cipher, one might rotate the alphabet so A becomes L which gives us a translation table of:

plaintext: ABCDEFGHIJKLMNOPQRSTUVWXYZ
encrypted: LMNOPQRSTUVWXYZABCDEFGHIJK

Making the encrypted message read "ESP VTYR TD OPLO". However, Vigenère gives us multiple encryption lines (or "alphabets"), one for each letter of the keyword:

plaintext: ABCDEFGHIJKLMNOPQRSTUVWXYZ
encrypted: LMNOPQRSTUVWXYZABCDEFGHIJK (1)
encrypted: OPQRSTUVWXYZABCDEFGHIJKLMN (2)
encrypted: YZABCDEFGHIJKLMNOPQRSTUVWX (3)
encrypted: ABCDEFGHIJKLMNOPQRSTUVWXYZ (4)
encrypted: LMNOPQRSTUVWXYZABCDEFGHIJK (5)
encrypted: TUVWXYZABCDEFGHIJKLMNOPQRS (6)
encrypted: YZABCDEFGHIJKLMNOPQRSTUVWX (7)

Using this system, we start by encrypting the first letter of the message with the first alphabet then we use the second alphabet for the second letter and so on. When we do the eighth letter of the message, we are out of alphabets so we start back at the first, and repeat this behavior until the entire message is encrypted. Now our message reads "EVC VBLR GS WCLR".

With the new text, we no longer see that the last word starts and ends with the same letter. Likewise, we can no longer do simple frequency analysis to figure out which letter is the most common and therefore most likely to be "E" (in English). Though we can do this if we know or can find the key length.

Anyway, now that we see how to do it, we can create the code. Below is "Vigen.java" which does just that with a little twist: it uses a different plaintext alphabet. In particular, it does A-Z followed by a-z (so we can mix case) then it uses 0-9 and ends with ~!@#$%^&*()_+-=,./<>?;:[]\{}| which covers all characters on the keyboard but the single and double quotes. The code also is written to be a little dense so casual observers won't know what it does.

If you prefer a well-documented, feature-friendly version, try the Vigenere.jar file. This executable jar contains the source and class files for your perusal and modification.

AttachmentSize
Vigen.java1.36 KB
Vigenere.java3.63 KB