Compute an adler32 checksum.
committer: mfx <mfx> 980609412 +0000
This commit is contained in:
@@ -89,6 +89,11 @@ print <<"EOF";
|
|||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$s = $ident;
|
||||||
|
$s =~ tr/a-z/A-Z/;
|
||||||
|
$s .= "_ADLER32";
|
||||||
|
printf("#define %s 0x%08x\n\n", $s, &adler32($data));
|
||||||
|
|
||||||
printf("unsigned char %s[%d] = {", $ident, $n);
|
printf("unsigned char %s[%d] = {", $ident, $n);
|
||||||
for ($i = 0; $i < $n; $i++) {
|
for ($i = 0; $i < $n; $i++) {
|
||||||
if ($i % 16 == 0) {
|
if ($i % 16 == 0) {
|
||||||
@@ -113,4 +118,26 @@ select(STDOUT);
|
|||||||
undef $delim;
|
undef $delim;
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
|
|
||||||
|
# /***********************************************************************
|
||||||
|
# //
|
||||||
|
# ************************************************************************/
|
||||||
|
|
||||||
|
sub adler32 {
|
||||||
|
local($d) = @_;
|
||||||
|
local($n) = length($d);
|
||||||
|
local($i);
|
||||||
|
local($s1) = 1;
|
||||||
|
local($s2) = 0;
|
||||||
|
|
||||||
|
for ($i = 0; $i < $n; $i++) {
|
||||||
|
$s1 += ord(substr($d, $i, 1));
|
||||||
|
$s2 += $s1;
|
||||||
|
$s1 %= 65521;
|
||||||
|
$s2 %= 65521;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($s2 << 16) | $s1;
|
||||||
|
}
|
||||||
|
|
||||||
# vi:ts=4:et
|
# vi:ts=4:et
|
||||||
|
|||||||
Reference in New Issue
Block a user