caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] printable digest strings
@ 2001-05-03 22:32 Miles Egan
  2001-05-04  9:15 ` Hendrik Tews
  2001-05-04  9:37 ` Xavier Leroy
  0 siblings, 2 replies; 11+ messages in thread
From: Miles Egan @ 2001-05-03 22:32 UTC (permalink / raw)
  To: caml-list

I can't seem to find a function to create printable versions of the digest
strings generated by the digest module, like the output of the common unix
md5sum utility.  Am I missing something or does it not exist?  If not, it might
be a handy addition to the Digest module.  At the moment I'm using this fairly
gross code of my own:

let hexchar nibble =
  let ac = Char.code 'a' in
  let zc = Char.code '0' in
  if nibble > 9 then
    Char.chr (nibble + ac - 10)
  else
    Char.chr (nibble + zc)

let hexstring s =
  let
    j = ref 0 and
    h = String.create (String.length s * 2) in
    for i = 0 to (String.length s - 1) do
      let
        high = ((Char.code s.[i]) lsr 4) land 0xf and
        low = (Char.code s.[i]) land 0xf in
        let _ = h.[!j] <- hexchar high in
        let _ = j := !j + 1 in
        let _ = h.[!j] <- hexchar low in
        j := !j + 1
    done;
    h

-- 
miles
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2001-05-07 18:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-03 22:32 [Caml-list] printable digest strings Miles Egan
2001-05-04  9:15 ` Hendrik Tews
2001-05-04  9:37 ` Xavier Leroy
2001-05-04 14:00   ` Miles Egan
2001-05-04 14:50     ` Brian Rogoff
2001-05-04 20:27   ` Chris Hecker
2001-05-04 22:54     ` Miles Egan
2001-05-06 18:56     ` [Caml-list] Wserver: Values of global variables lost Mattias Waldau
2001-05-07  8:58       ` Daniel de Rauglaudre
2001-05-07 17:00       ` Mattias Waldau
2001-05-07 18:16         ` Daniel de Rauglaudre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).