# Cyclical Vigenere poem!

This is a new idea I just came up with. I'm going to tell you exactly how I constructed the following ciphertext, and your task is to extract the plaintext. If you really want a challenge, you can try attacking the ciphertext just as a string of cryptograms without reading the spoilertag below, but I don't think that will be doable!

## Ciphertext

npjojoosdbtdppcvidztixnuuslbnzleug
npjbalduouffllvsatdsmxnsxzcabqfs
uvibqpqlagisedeqaughqdzrxabtkiuglbbm
ocarfeaxmbmlixeyvcckmsyrxvtqsshiuj
ocagmpyayinymbbywvbzfjzpghtimdzxafgmhtf
tozfityzjuqwcxtfqrkaynxevnlwzdzmg
toziowbkdnqsmqnhsxicqqfammbwlpbctvrpbhvx
tozilwxmelxajawrlkuqkyuvypnwnpklyphim
miarixjhmglycdswygcddzpchotqjaxa
inxhrxjgdpkpvxszhtuzmrghsfgrjnpff
buezvbixobbganbagtmabfjrwhalhodiw
otzjtnpyzpghazuaxsqugtlgsyhlk
vmshvlnyeihqdnaojosqyeinquqyfhyifrmpfgz

## Methodology

Here's what I did to create the ciphertext.

I started with 13 lines of poetry, and applied the Vigenere cipher to each line using the next line as the key (cycling round so that the 1st line is the key for the 13th line).

In case this is unclear, here's a simple example of this encryption method being applied. Plaintext:

Cat
Rabbit
Dog

Ciphertext:

ubv
vpifxa
gpa

Your task is to devise a decryption method to find the plaintext given the above ciphertext. You may use Vigenere software such as this, but brute-forcing by e.g. writing a program to test all the possibilities isn't allowed.

## Have fun!

• Great puzzle! I've half an idea, let's see if works... – leoll2 Apr 26 '15 at 17:06
• Isn't it just solving a system of linear equations? Add the even lines up, subtract the odd lines, and divide by 2. – Joe Z. Apr 26 '15 at 17:06
• Although I understand that modulo 26 that might not always work. – Joe Z. Apr 26 '15 at 17:06

## 2 Answers

There are an odd number of lines. If every other line is added and the skipped lines are subtracted, the result will be a line added to itself. There are then two possibilities for each character in the original line.

The possibilities for line 4 are:

aadleaiefghejbeldgbdaekaeffaa
nnqyrnvrsturworyqtoqnrxnrssnn


"andleavestheworldtodarkness" can be read. Now, with part of a line reconstructed, it can be used as a key for the preceding and following lines, so we can get the beginnings of all of the lines:

thecurfewtollstheknellofparti
thelowingherdwindslowlyoerthe
theploughmanhomewardplodshisw
andleavestheworldtodarknessan
nowfadestheglimmringlandscape
andalltheairasolemnstillnessh
savewherethebeetlewheelshisdr
anddrowsytinklingslullthedist
savethatfromyonderivymantledt
themopingowldoestothemooncomp
ofsuchaswandringnearhersecret
molestherancientsolitaryreign
beneaththoseruggedelmsthatyew


Line 12 is now complete, and the last characters of line 11 can be decrypted by wrapping it around. The full poem can be recovered (spacing and punctuation added):

The curfew tolls the knell of parting day

The lowing herd winds slowly o'er the lea

The ploughman homeward plods his weary way

And leaves the world to darkness and to me

Now fades the glimm'ring landscape on the sight

And all the air a solemn stillness holds

Save where the beetle wheels his droning flight

And drowsy tinklings lull the distant folds

Save that from yonder ivy mantled tow'r

The moping owl does to the moon complain

Of such as wand'ring near her secret bow'r

Molest her ancient solitary reign

Beneath those rugged elms, that yew-tree's shade

These are the first 13 lines of "Elegy Written in a Country Churchyard" by Thomas Gray.

• Great one! I was trying to apply a very similar strategy, but I got stuck in C++ and wasn't fast enough. Well done! – leoll2 Apr 26 '15 at 18:28
• Well done! My apologies for the error; I'll correct the OP. Could you also mention the name of the poem of which these are the first 13 lines? – Rand al'Thor Apr 26 '15 at 18:42
• The OP has now been corrected - sorry again for the mistake. Also, welcome to Puzzling.SE! :-) – Rand al'Thor Apr 26 '15 at 18:44
• You're missing a few words off the last line there. – Joe Z. Apr 26 '15 at 18:59

This is not an answer (actually it contains an answer!) but an important observation about this encryption algorithm. The main answer has been posted by user 11810.

When you encrypt a message using this algorithm, you lose information about the original data.
Let's consider these examples:

A -> B
A -> B

N -> B
N -> B

M -> B
O -> B
...

As you can see, when you try to decrypt BB you obtain 26 different strings! Which one is the original one? You can't know!
Specifically, if you have an even number of lines to decrypt, there are exactly $26$ different valid "original" messages.
On the contrary, when you have an odd number of lines to decrypt, there are only $2$ different valid "original" messages!
Consider these lines to encrypt:
A -> B
A -> B
A -> B

N -> B
N -> B
N -> B

Again, as you can see, decrypting BBB doesn't returns a unique solution.

In our problem we were lucky because we had an odd number of lines ($13$), so we could identify the poetry because only one solution was meaningful. Do you want to know the ugly sister of the poetry? You can easily obtain it applying ROT13 to the original one! Here it is:

gurphesrjgbyyfgurxaryybscnegv
gurybjvatureqjvaqfybjylbregur
gurcybhtuznaubzrjneqcybqfuvfj
naqyrnirfgurjbeyqvaqnexarffna
abjsnqrfgurtyvzzevatynaqfpncr
naqnyygurnvenfbyrzafgvyyarffu
fnirjurergurorrgyrjurryfuvfqe
naqqebjflgvaxyvatfyhyygurqvfg
fnirgungsebzlbaqrevilznagyrqg
gurzbcvatbjyqbrfgbgurzbbapbzc
bsfhpunfjnaqevatarneurefrperg
zbyrfgurenapvragfbyvgnelervta
orarngugubfrehttrqryzfgunglrj

Isn't it beautiful? If you have some time to waste, verify that this encrypts to the ciphertext given by rand al'thor!

• Wow, this is great! I hadn't realised there were 2 possible solutions - luckily only one of them will make sense for almost any possible plaintext. I was thinking of posting another puzzle with an even number of lines to make it harder... – Rand al'Thor Apr 26 '15 at 19:21
• @leoll2 I was actually trying to figure that out myself by posting this problem on Math.SE. – Joe Z. Apr 26 '15 at 22:53