Skip to content

Instantly share code, notes, and snippets.

@UberMouse
Created March 6, 2014 22:36
Show Gist options
  • Save UberMouse/9401285 to your computer and use it in GitHub Desktop.
Save UberMouse/9401285 to your computer and use it in GitHub Desktop.
Quick and easy vigenere encoding
val Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
def vigenere(key:String, message:String) = {
val keyLength = key.length
val builder = new StringBuilder(message.length)
for((c, i) <- message.zipWithIndex) {
val index = (c + key(i % keyLength)) % 26
builder.append(Alphabet(index))
}
builder.toString()
}
vigenere("REDDIT", "TODAYISMYBIRTHDAY")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment