/[mdap]/protocol/calc.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /protocol/calc.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 11 by dpavlin, Sun Apr 22 22:39:33 2007 UTC revision 12 by dpavlin, Sun Apr 22 22:50:42 2007 UTC
# Line 11  my $file = shift @ARGV || die "usage: $0 Line 11  my $file = shift @ARGV || die "usage: $0
11    
12  my $p = read_file( $file ) || die "can't read $file: $!";  my $p = read_file( $file ) || die "can't read $file: $!";
13    
14  my $orig = $2 if ( $p =~ s/(\r\n)(\w+)$/$1/s );  my $orig = $1 if ( $p =~ s/(..)$//s );
15    
16  print "ORIGINAL checksum: $orig\n";  print "ORIGINAL checksum: $orig\n";
17    
# Line 19  my $sum = 0; Line 19  my $sum = 0;
19  for my $i ( 0 .. length($p) ) {  for my $i ( 0 .. length($p) ) {
20          my $c = substr($p,$i,1);          my $c = substr($p,$i,1);
21          my $o = ord($c);          my $o = ord($c);
22          my $h = sprintf('%x',$o);          my $h = sprintf('%02x',$o);
23  #       $sum += $o;  #       $sum += $o;
24          $sum ^= $o;          $sum ^= $o;
25          print "# $i '$c' $o 0x$h -- $sum 0x", sprintf('%x',$sum),"\n";          printf("# %-2d '%s' %2d %02x -- %2d %02d\n", $i,$c,$o,$o,$sum,$sum);
26  }  }
27    
28  print "ORIGINAL checksum: $orig\n";  printf("checksum: %s == %02x\n", $orig, $sum);

Legend:
Removed from v.11  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.26