Monday, 21 January 2013

Hundreds - Next Riddle (59)

From my sources online, I determined that this riddle was a Vigenère cipher. Vigenère ciphers are similar to Caesar ciphers, except instead of the contacts 3 character shift, it has a shift that is based on a keyword. The keyword is repeated until it is the same length as the text to encode.  i.e. If LEMON was the keyword, you would repeat it like so

LEMONLEMONLEMONLEMON

for a message like

THISISASECRETMESSAGE

Then, you take the location of each letter in the alphabet and add them together to get the new letter (it's explained more complexly on wikipedia, but this is what it boils down to). This would produce the following secret message:

ELUGVDEESPCIFARDWMUR

Thus, to decode one of these, you simply need a keyword, and subtract the keyword's letters from the encoded message's. This is the ruby script I wrote to do this:


file = File.new("vigenere.txt", "r")
cypher = file.gets
file.close

$key = {}
keyword = ARGV[0]


$letterArray = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

string = ""
count = 0
cypher.each_byte { |i|
   if(i.chr == " ")
      string = string + " "
   else
      keywordLetter = keyword.split('')[count%keyword.length]
      offset = $letterArray.index(keywordLetter)
      index = $letterArray.index(i.chr)
      string = string + $letterArray[(index-offset)%26]
      count+=1
   end
}
puts "\n"+string+"\n\n"

The script takes a single argument, which is the keyword, and tries to decode the message. With that taken care of, all that was left was to guess the keyword. Judging by the previous messages, the keyword had something to do with a harp or a chord or something. I tried pretty much everything I could think of, and then tried RADIUS after looking at the cipher's achievements page. The secret message:

Being part of a bad riddle that nobody cares about.


No comments:

Post a Comment