Last active
January 2, 2016 13:39
-
-
Save film42/8311648 to your computer and use it in GitHub Desktop.
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 cipher = Map('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' -> 'з', ' ' -> '@') | |
lazy val reverse_cipher = cipher.map(_.swap) | |
def encrypt(word: String) = | |
word.flatMap(x => cipher(x.toLower).toString) | |
def decrypt(word: String) = | |
word.flatMap(x => reverse_cipher(x.toLower).toString) | |
// Examples | |
encrypt("hello world") //=> "челло@шорлд" | |
decrypt("челло@шорлд") //=> "hello world" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment