Created
March 6, 2014 22:36
-
-
Save UberMouse/9401285 to your computer and use it in GitHub Desktop.
Quick and easy vigenere encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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