2019-07-28 18:27:33 +00:00
|
|
|
{- modified version of MD5 from http://www.cs.ox.ac.uk/people/ian.lynagh/md5
|
|
|
|
-
|
|
|
|
- Copyright (C) 2001 Ian Lynagh
|
|
|
|
- License: GPL 2
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Utility.MD5 where
|
|
|
|
|
|
|
|
import Data.Bits
|
|
|
|
import Data.Word
|
2019-12-11 18:12:22 +00:00
|
|
|
import Data.Char
|
2019-07-28 18:27:33 +00:00
|
|
|
|
2019-12-11 18:12:22 +00:00
|
|
|
display_32bits_as_dir :: Word32 -> [Word8]
|
2019-07-28 18:27:33 +00:00
|
|
|
display_32bits_as_dir w = trim $ swap_pairs cs
|
|
|
|
where
|
|
|
|
-- Need 32 characters to use. To avoid inaverdently making
|
|
|
|
-- a real word, use letters that appear less frequently.
|
2019-12-11 18:12:22 +00:00
|
|
|
chars = map (fromIntegral . ord) (['0'..'9'] ++ "zqjxkmvwgpfZQJXKMVWGPF")
|
2019-07-28 18:27:33 +00:00
|
|
|
cs = map (\x -> getc $ (shiftR w (6*x)) .&. 31) [0..7]
|
|
|
|
getc n = chars !! fromIntegral n
|
|
|
|
swap_pairs (x1:x2:xs) = x2:x1:swap_pairs xs
|
|
|
|
swap_pairs _ = []
|
|
|
|
-- Last 2 will always be 00, so omit.
|
|
|
|
trim = take 6
|