Skip to content

Instantly share code, notes, and snippets.

@buccolo
Created December 10, 2011 21:00
Show Gist options
  • Save buccolo/1456375 to your computer and use it in GitHub Desktop.
Save buccolo/1456375 to your computer and use it in GitHub Desktop.
Vigenere Encryption
#!/usr/bin/ruby
class String; def ord; self[0]; end; end
phrase = "tobeornottobethatisthequestion"
keyword = "hamlet"
len = keyword.length
keyindex = 0
phrase.each_char do |c|
print ((c.ord - 97 + keyword[keyindex].ord - 97) % 26 + 97).chr
keyindex = (keyindex + 1) % len
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment