Skip to content

Instantly share code, notes, and snippets.

@film42
Last active January 2, 2016 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save film42/8311648 to your computer and use it in GitHub Desktop.
Save film42/8311648 to your computer and use it in GitHub Desktop.
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