Skip to content

Instantly share code, notes, and snippets.

@antekone
Created June 23, 2016 08:57
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 antekone/405cef8c44af3b5aea6e59d9b9be43da to your computer and use it in GitHub Desktop.
Save antekone/405cef8c44af3b5aea6e59d9b9be43da to your computer and use it in GitHub Desktop.
import qualified Data.ByteString.Lazy as BL
import Data.Binary.Get
import Data.Word
import Data.Bits
import Data.Char
readArray :: Get [Word8]
readArray = do
empty <- isEmpty
if empty
then return []
else do
byte <- getWord8
rest <- readArray
return (byte : rest)
decodeCharonCache :: Int -> [Int] -> [Int]
decodeCharonCache i [] = []
decodeCharonCache i (x:xs) =
[xorVal `xor` x `xor` 0x6A] ++ decodeCharonCache (i + 1) xs
where
xorVal = (i `div` 256) `xor` (i `mod` 256)
main :: IO ()
main = do
input <- BL.getContents
putStr $ map chr $ decodeCharonCache 0 $ map (\x -> fromIntegral x :: Int) (runGet readArray input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment