-
-
Save KWMalik/3209710 to your computer and use it in GitHub Desktop.
Cryptography coursera class exercise #3.
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
{-# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
% runhaskell Main.hs
5b96aece304a1422224f9a41b228416028f9ba26b0d1058f400200f06a589949