Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created February 18, 2015 11:44
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 shigemk2/07396e6eb70ec7690b52 to your computer and use it in GitHub Desktop.
Save shigemk2/07396e6eb70ec7690b52 to your computer and use it in GitHub Desktop.
import Data.Char
-- ordで数値に変換して、offsetをプラスして、それをchrで元に戻している。
-- ordやchrがあれば、とりあえずBrainfuckのインタプリタが作れそう。ただ、ファイルを読み込むので副作用を考慮しないといけないけども。
encode :: Int -> String -> String
encode offset msg = map (\c -> chr $ ord c + offset) msg
-- 若干手抜き
decode :: Int -> String -> String
decode shift msg = encode (negate shift) msg
main = do
print $ encode 3 "hey mark"
print $ encode 5 "please instruct your men"
print $ encode 1 "to party hard"
print $ decode 3 "kh|#pdun"
print $ decode 5 "uqjfxj%nsxywzhy%~tzw%rjs"
print $ decode 1 "up!qbsuz!ibse"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment