You may be interested in this implementation of the Adler-32 checksum algorithm (see Adler-32).

use warnings; use strict; use constant MOD_ADLER => 65521; print Adler32('abc def ghi') . "\n"; print Adler32('acb def ghi') . "\n"; sub Adler32 { my $data = shift; my $scan = 0; my $len = length $data; my $a = 1; my $b = 0; while ($len) { my $tlen = $len > 5550 ? 5550 : $len; $len -= $tlen; do { $a += ord (substr $data, $scan++, 1); $b += $a; } while (--$tlen); $a = ($a & 0xffff) + ($a >> 16) * (65536 - MOD_ADLER); $b = ($b & 0xffff) + ($b >> 16) * (65536 - MOD_ADLER); } $a -= MOD_ADLER if $a >= MOD_ADLER; $b = ($b & 0xffff) + ($b >> 16) * (65536 - MOD_ADLER); $b -= MOD_ADLER if $b >= MOD_ADLER; return ($b << 16) | $a; }

Prints:

378209230 378274766

Note that this is a translitteration from the C code - $a and $b would be better renamed. :)


DWIM is Perl's answer to Gödel

In reply to Re: Quick and Dirty Hash by GrandFather
in thread Quick and Dirty Hash by clancey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.