Skip to content

Commit

Permalink
crypto-hashing.hs
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin committed Aug 30, 2019
1 parent 561f36e commit 26b9cea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
17 changes: 17 additions & 0 deletions crypto-hashing.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Crypto.Hash
import Data.ByteString (ByteString)
import qualified Data.ByteString.UTF8 as UTF8
import Data.ByteArray.Encoding

sha256 :: String -> String
sha256 input = result
where
bytes = UTF8.fromString input :: ByteString
digest = hashWith SHA256 bytes :: Digest SHA256
hex = convertToBase Base16 digest :: ByteString
result = UTF8.toString hex :: String

main =
do
putStrLn ("sha256(abc) = " ++ sha256 "abc")
putStrLn ("sha256(hello) = " ++ sha256 "hello")
2 changes: 2 additions & 0 deletions outputs/crypto-hashing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sha256(abc) = ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
sha256(hello) = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
4 changes: 3 additions & 1 deletion tools/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

haskellPackages.ghcWithPackages (p: [
p.containers
p.cryptonite
p.memory
p.mwc-random
p.hashable
p.stm
p.text
p.time
p.utf8-string
])
1 change: 1 addition & 0 deletions tools/outputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ in
linkFarm "haskell-phrasebook-outputs" [
(run' "branching.txt" ../branching.hs { sed = ["s!^It's .* noon$!It's ... noon!"]; })
(run "common-types.txt" ../common-types.hs)
(run "crypto-hashing.txt" ../crypto-hashing.hs)
(run "for-loops.txt" ../for-loops.hs)
(run "hashing.txt" ../hashing.hs)
(run "hello-world.txt" ../hello-world.hs)
Expand Down

0 comments on commit 26b9cea

Please sign in to comment.