# Vigenere Cipher - help with decryption (by hand)

So this is a Vigenere cipher-text

``````EORLL TQFDI HOEZF CHBQN IFGGQ MBVXM SIMGK NCCSV
WSXYD VTLQS BVBMJ YRTXO JCNXH THWOD FTDCC RMHEH
SNXVY FLSXT ICNXM GUMET HMTUR PENSU TZHMV LODGN
MINKA DTLOG HEVNI DXQUG AZGRM YDEXR TUYRM LYXNZ
ZGJ
``````

The index of coincidence gave a shift of six (6): I know this is right (I used an online Java applet to decrypt the whole thing using the key 'QUARTZ').

However, in this question we are only told the first and last two letters of the Key - 'Q' and 'TZ.'

So far I have split the ciphertext into slices using this awesome applet. So the first slice is 0, k, 2k, 3k, 4k; the second is 1, k + 1, 2k + 1, 3k + 1; et cetera.

``````KeyPos=0: EQEQQSCXQJJHDEYIUTSVMTVUMTYJ
KeyPos=1: OFZNMICYSYCWCHFCMUULILNGYUX
KeyPos=3: LICFVGVVVTXDRNSXTPZDKGDZERZ
KeyPos=4: LHHGXKWTBXHFMXXMHEHGAHXGXMZ
KeyPos=5: TOBGMNSLMOTTHVTGMNMNDEQRRLG
``````

My idea was to calculate the highest-frequency letter in each block, hoping that the most frequent letter would give me some clue as to how to find 'U,' 'A' and 'R.' However, the most frequent letters in these blocks are:

``````KeyPos=0: Q,4 T,3 E,3, J,3
KeyPos=1: C,4 U,3 Y,3
KeyPos=2: N,4 O,3 R,3 D,3 B,2
KeyPos=3: V,4 D,3 Z,3
KeyPos=4: H,6 X,6 M,3 G,3
KeyPos=5: M,4 T,4 N,3 G,3
``````

Which yields QCNVHM, or QUNVHM (being generous), neither of which are that close to QUARTZ. There are online applets that can crack this no problem, so it mustn't be too short a text to yield decent frequency counts from the blocks.

I guess I must be approaching this the wrong way. I just hoped one of you might be able to offer some clue as to where I am going wrong.

Thanks for any help!

You are approaching this the wrong way. What you have here is the ciphertext. This means that the most frequent letter in each block will (or should) correspond to the most frequent letter in the cleartext. With a long enough text, you can assume that this is the letter 'E'. The most frequent letter in each position is not the letter of the keyword.

This means that you can find each letter of the key using the most frequent letter at a position and its offset from the letter 'E'. Knowing that the letter 'A' will give you a offset of 0, and the letter 'Z' will give you a offset of 25, it is trivial to guess the original key.

However, this only works for longer texts, since the letter distribution is easy enough to mess up in shorter ones. Using the cleartext from your question, the most frequent letter is, in fact, 'O', not 'E'. In addition, because the text is so short, the letter frequencies at each of the positions of the key are even more skewed.

I am not sure how you managed to decode this automatically. The only way I can think of would be to check for dictionary words in both the key and the resulting output, ignoring any keys which do not make sense.

In general, the Vigenere cipher can be cracked easily for longer texts with shorter keys. If you have a short text (like here), or a longer key, then it gets harder. Ideally, you would use a random key that is longer than the plaintext, so it never repeats, which guarantees that the ciphertext cannot be decoded without the key.

Copying my answer over from StackOverflow:

I don't have a programmatic solution for cracking the original ciphertext, but I was able to solve it with a little mind power and some helpful JavaScript.

I started by using this page (now not functional) and the information you supplied. Provide the ciphertext, a key length of 6 and hit initialize. What's nice about the approach here is that unknowns in either the plaintext or key are left as hyphens.

Update the key, adding only what you know `Q---TZ` and click 'update plaintext'. At this point we know:

o---sua---opo---oca---nha---enc---rom---dth---ama---int---ept---our---mun---tio---ewi---eus---the---ond---loc---onf---now---hed---off---ere---nsw---esd---tmi---ght

Here's where I applied a bit of brain power. You start recognizing bits of the plaintext. `the`, `now` and `off` make an appearance. At the end, there's `ght` - this made me think the prior letter is likely a vowel. For example `light` or `thought`. I replaced the corresponding hyphen with `u` and clicked update keyword to find what letter would have produced that combination. The matching letter turns out to be `F`. I think updated the plaintext to see the results. They didn't look promising. So I tried `i` instead which resulted in:

o--usua--ropo--loca--onha--eenc--prom--edth--eama--eint--cept--gour--mmun--atio--wewi--beus--gthe--cond--yloc--ionf--mnow--thed--poff--mere--insw--nesd--atmi--ight

Now we're getting somewhere. At the start I see something that might be `usual`, and further in I see `int--cept` and near the end `w--nesd--` `at` `mi--ight`. Voila. Filling in the letters for `wednesday` and updating the keyword yielded `QUARTZ`.

... So, how to port this approach to code? Not sure about the best way to do that just yet. The idea of using the known characters in the key, partially decrypting the ciphertext and brute forcing the rest is appealing. But without a dictionary handy, I'm not sure what the best brute-forcing method would be...

To be continued (maybe)...

Working off what Tails has found above:

o--usua--ropo--loca--onha--eenc--prom--edth--eama--eint--cept--gour--mmun--atio--wewi--beus--gthe--cond--yloc--ionf--mnow--thed--poff--mere--insw--nesd--atmi--ight

I see this as the following by simply guessing the missing letters:

``````oUR
usuaAL
ropo--
locaTIon
haS
Been
cOMpromISed
th--eama--e
intERceptINg
our
COmmunICatioNS
we
wiLL
be
usINg
the
--cond--y
locATion
fROm
now
ON
the
dROp
off
--mere--insw--nesd--
at
miDNight
``````