Copyright | (c) Eric Mertens 2021 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
https://adventofcode.com/2015/day/4
Compute the MD5 hashes of things.
Synopsis
- main :: IO ()
- solve :: String -> Int64 -> Maybe Int
- adventHash :: String -> Int -> ByteString
- zeros :: Int64 -> ByteString -> Bool
- data Context = Context !Word32 !Word32 !Word32 !Word32
- md5 :: ByteString -> ByteString
- finish :: Context -> ByteString
- envelope :: ByteString -> ByteString
- toBlocks :: ByteString -> [Vector Word32]
- addState :: Context -> Context -> Context
- addBlock :: Context -> Vector Word32 -> Context
- data Round = Round !Int !Word32 !Int
- doRound :: Vector Word32 -> Mixer -> Context -> Round -> Context
- type Mixer = Word32 -> Word32 -> Word32 -> Word32
- toFixedByteString :: Int -> Builder -> ByteString
- stable1 :: [Int]
- stable2 :: [Int]
- stable3 :: [Int]
- stable4 :: [Int]
- ktable1 :: [Word32]
- ktable2 :: [Word32]
- ktable3 :: [Word32]
- ktable4 :: [Word32]
- gtable1 :: [Int]
- gtable2 :: [Int]
- gtable3 :: [Int]
- gtable4 :: [Int]
- initialState :: Context
Documentation
solve :: String -> Int64 -> Maybe Int Source #
Find the smallest, positive integer that has the specified number of leading zeros in its hex representation.
:: String | player key |
-> Int | number to hash |
-> ByteString |
The "advent hash" of a number is the MD5 digest of a key string and a ASCII, base-10 representation of the number.
zeros :: Int64 -> ByteString -> Bool Source #
Test that the first n
digits in hex-representation of
the digest are 0
.
md5 :: ByteString -> ByteString Source #
finish :: Context -> ByteString Source #
Extract the final MD5 digest from a context
envelope :: ByteString -> ByteString Source #
Pad out an input string to be suitable for breaking into
blocks for MD5. This algorithm pads with a 1
and then
as many 0
bytes as needed so that when the 8-byte length
is added that the whole message's length is a multiple of
64-bytes.
toBlocks :: ByteString -> [Vector Word32] Source #
Break a bytestring with a length that is a multiple of 64 into blocks of 16 32-bit words loaded in little-endian order.
addState :: Context -> Context -> Context Source #
Point-wise addition of the components of a Context
toFixedByteString :: Int -> Builder -> ByteString Source #