Created
February 18, 2015 11:44
-
-
Save shigemk2/07396e6eb70ec7690b52 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
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