in reply to Alternative Perl encryption module

This is not an answer, sorry. I searched CPAN and found many modules dealing with Digest; the most common ones (MD2, MD4, MD5, SHA-1) produce strings longer than 20 bytes... Here is the code I used to test it:

#!/usr/bin/perl use strict; use Digest; my $data = "message to be digested"; for ('MD2', 'MD4', 'MD5', 'SHA-1') { showme($_, Digest->new($_), $data); } exit; sub showme { my ($mode, $digest, $data) = @_; $digest->add($data); print "Digest::$mode\n"; print "binary (length): ", length($digest->digest), "\n"; print "hex : ", $digest->hexdigest, "\n"; if ($digest->can('b64digest')) { print "base64 : ", $digest->b64digest, "\n"; } print "\n"; } __END__ # output Digest::MD2 binary (length): 16 hex : 8350e5a3e24c153df2275c9f80692773 base64 : g1Dlo+JMFT3yJ1yfgGkncw Digest::MD4 binary (length): 16 hex : 0962f09cec91822209796b504862847b Digest::MD5 binary (length): 16 hex : d41d8cd98f00b204e9800998ecf8427e base64 : 1B2M2Y8AsgTpgAmY7PhCfg Digest::SHA-1 binary (length): 20 hex : da39a3ee5e6b4b0d3255bfef95601890afd80709 base64 : 2jmj7l5rSw0yVb/vlWAYkK/YBwk

Given these digest methods, only binary format seems suitable for your needs... does anybody know of other algorithms?

Ciao, Valerio

Replies are listed 'Best First'.
Re: Re: Alternative Perl encryption module
by mowgli (Friar) on Mar 10, 2003 at 13:02 UTC

    Given these digest methods, only binary format seems suitable for your needs... does anybody know of other algorithms?

    Speaking about needs, why is it important that the digest be at most 10 bytest in length, anyway? I quite seriously don't think there is a widely-used, well-known digest function that uses only 10 bytes, especially since longer digest sizes are usually considered to be a good thing.

    Maybe the original author could provide some background on this.

    --
    mowgli

      Without looking at the subject, I would assume that the author needs a hashing algorithm, but not for cryptographic purposes. In which case, a smaller hash is just fine as long as you know how to take care of collisions (the book "Intro to Algorithms" handles this by putting colliding data into a linked list which is walked through to find the specific entry you need).

      But since the subject specifies encryption, I would say the author needs to research more about cryptography.

      ----
      Reinvent a rounder wheel.

      Note: All code is untested, unless otherwise stated

        *nods* In case cryptographic strength is not needed, one might just use an SHA-1 mac and cut it in half, so to speak; I have no idea what conditions would still hold with regard to the absence of collisions if one did that, but depending on the problem at hand, it might be worth looking into.

        --
        mowgli