calc_adler32 :: String->Int->Int->Int
calc_adler32 [] a b = (b `shiftL` 16) .|. a
calc_adler32 str a b =
let ap = (a + (ord $ head str)) `mod` mod_adler
bp = (ap + b) `mod` mod_adler
in calc_adler32 (tail str) ap bp
crc32 :: String -> Int
crc32 str = calc_adler32 str 1 0
*Main> crc32 "abc"
38600999
No comments:
Post a Comment