in reply to Re^3: MD5 Hash
in thread MD5 Hash

I like the idea of checking the 1st 64k of the md5 hash. How would i accomplish that from the code i posted above.

Replies are listed 'Best First'.
Re^5: MD5 Hash
by roboticus (Chancellor) on Dec 02, 2009 at 14:42 UTC
    Karger78:

    Instead of handing a file handle to $ctx, you would instead read 64K of data from the file handle, and give that chunk of data to $ctx. So it should be something like:

    sub md5sum{ my $file = shift; my $digest = ""; eval{ open(FILE, $file) or die "Can't find file $file\n"; my $data; read FILE, $data, 65536 or die "Can't read from $file\n$!"; my $ctx = Digest::MD4->new; $ctx->add($data); $digest = $ctx->hexdigest; close(FILE); }; if($@){ print $@; return ""; } return $digest; }

    Note: The code is untested...

    ...roboticus