in reply to Compact MD5 representation

An email client might wrap the display of the URL onto a second line, but if it's worth it's salt it won't actually stick a newline in the string, which *would* wreck your URL (in the sense of making an unusable hypertext link, for clients that support that sort of thing).

Other than this mostly display-related issue, I can't think of what you might mean by a URL not fitting into an email. If it's aesthetics you're worried about, well, you already have that ugly string in there, so might as well overdo it while you're into it. (as Steve Vai would say).

So if you want to provide clickable links, try it with the full-dress md5 hash. An alternative thing is to truncate the hash and hope for the best, i.e. grab the last 16 characters and hope none of the values collides? Or maybe I shouldn't recommend anything so reckless ...

Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Replies are listed 'Best First'.
Re: Re: Compact MD5 representation
by Anonymous Monk on Mar 20, 2001 at 02:55 UTC
    There's nothing reckless about taking only part of an md5 hash. The MD5 algorithm is a good hashing algorithm and ensures that small changes to the source will result in big changes to the hash, so you don't have to worry about similar inputs producing similarities in the (first|last|middle) X bits. As for hoping there are no collisions, reducing the hash size does increase the chance of collision, but there's no guarantee that each full length md5 will be unique. It should be trivial to write code which checks for a collision and fixes it (by appending characters onto the input data until the md5 is unique, for example).
      I'm a php person, so I can't offer code, but I do understand the question which is being asked.

      Rather than showing a url of /?a=123456, the questioner is looking for a url that says /?a=rqz instead. By using the full range of alphanumeric characters, he is hoping to reduce the MD5 from a 32 character string (using 0-9,a-f), into something much smaller, maybe a 12 character string (using 0-9, a-z). This has the benefit of being shorter, while still spanning the same range of values (2^32) as MD5.

      php has the function: string base_convert (string number, int frombase, int tobase), which I'm sure has an equivalent in perl. Once you find this function the problem is reduced to:

      $new_number = base_convert( md5('whatever'), 16, 36 ); // 10 digits + 26 alphanumeric

      Hopefully some perl guru will be able to point you in the right direction.

      --Robert

        That's sorta what was already being gotten at by using the _base64 version rather than the _hex version. Read the other responses in this thread.

        -- Randal L. Schwartz, Perl hacker

        and mysql has it just as easy: "SELECT CONV(md5, 16, 36) from table"