Subversion Repositories camp_sysinfo_client_3

Rev

Rev 244 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
52 rodolico 1
#! /usr/bin/env perl
2
 
3
# implementation of Fletcher's Checksum
4
# https://en.wikipedia.org/wiki/Fletcher's_checksum
5
# Actually, changed it to Adler
6
# https://en.wikipedia.org/wiki/Adler-32
7
 
8
use strict;
9
use warnings;
10
 
11
sub checksum {
12
 
13
   my $modulo = 65521;
14
 
15
   my $sum1 = 0;
16
   my $sum2 = 0;
17
 
18
   while ( my $a = shift ) {
19
      $sum1 = ( $sum1 + $a) % $modulo;
20
      $sum2 = ( $sum2 + $sum1 ) % $modulo;
21
   }
22
   return ( $sum2 << 16 ) | $sum1;
23
 
24
}
25
 
26
my $input = join( '', <> );
27
 
28
printf ( "%x\n", &checksum( unpack( "C*", $input ) ) );
29
 
30
1;