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"
Being part of a bad riddle that nobody cares about.
No comments:
Post a Comment