Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Created December 15, 2016 12:54
Show Gist options
  • Select an option

  • Save theburningmonk/6009a74d2d3408a4808a49b2b145dace to your computer and use it in GitHub Desktop.

Select an option

Save theburningmonk/6009a74d2d3408a4808a49b2b145dace to your computer and use it in GitHub Desktop.
let hex =
seq {
yield! Seq.zip { 0uy..9uy } { '0'..'9' }
yield! Seq.zip { 10uy..15uy } { 'a'..'f' }
}
|> Map.ofSeq
let hash (input : string) =
let bytes = input |> Encoding.UTF8.GetBytes |> md5.ComputeHash
let chars = Array.zeroCreate<char> (bytes.Length * 2)
bytes |> Seq.iteri (fun i b ->
chars.[i*2] <- hex.[b / 16uy]
chars.[i*2+1] <- hex.[b % 16uy])
new String(chars)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment