Skip to content

Instantly share code, notes, and snippets.

@MichaelBlume
Last active August 29, 2015 13:58
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 MichaelBlume/10347711 to your computer and use it in GitHub Desktop.
Save MichaelBlume/10347711 to your computer and use it in GitHub Desktop.
#!/usr/bin/runhaskell
import Data.Char
translate_char tmap c = helper tmap where
helper [] = c
helper ((c',ct):ps)
| c == c' = ct
| otherwise = helper ps
translate_string tmap = map $ translate_char tmap
cipher_helper s = do
putStrLn s
c1 <- getChar
c2 <- getChar
cipher_helper $ translate_string [(c1, c2)
,(c2, c1)
,(toUpper c1, toUpper c2)
,(toUpper c2, toUpper c1)] s
main = getLine >>= cipher_helper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment