Skip to content

Instantly share code, notes, and snippets.

@KWMalik
Forked from supki/Main.hs
Created July 30, 2012 20:04
Show Gist options
  • Save KWMalik/3209710 to your computer and use it in GitHub Desktop.
Save KWMalik/3209710 to your computer and use it in GitHub Desktop.
Cryptography coursera class exercise #3.
{-# LANGUAGE UnicodeSyntax #-}
import Control.Applicative ((<$>))
import Data.Monoid (mempty, (<>))
import Text.Printf (printf)
import Crypto.Hash.SHA256 (hash)
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
main ∷ IO ()
main = split 1024 <$> B.readFile "data/video1.mp4" >>= printAsHex . foldr (\x a → hash $ x <> a) mempty
where
printAsHex = putStrLn . concatMap (printf "%02x") . B.unpack
split ∷ Int → ByteString → [ByteString]
split n s
| B.null (B.drop n s) = [s]
| otherwise = xs : split n ys
where
(xs, ys) = B.splitAt n s
@KWMalik
Copy link
Author

KWMalik commented Jul 30, 2012

% runhaskell Main.hs
5b96aece304a1422224f9a41b228416028f9ba26b0d1058f400200f06a589949

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment