--- protocol/calc.pl 2007/04/22 22:39:33 11 +++ protocol/calc.pl 2007/04/22 22:50:42 12 @@ -11,7 +11,7 @@ my $p = read_file( $file ) || die "can't read $file: $!"; -my $orig = $2 if ( $p =~ s/(\r\n)(\w+)$/$1/s ); +my $orig = $1 if ( $p =~ s/(..)$//s ); print "ORIGINAL checksum: $orig\n"; @@ -19,10 +19,10 @@ for my $i ( 0 .. length($p) ) { my $c = substr($p,$i,1); my $o = ord($c); - my $h = sprintf('%x',$o); + my $h = sprintf('%02x',$o); # $sum += $o; $sum ^= $o; - 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); } -print "ORIGINAL checksum: $orig\n"; +printf("checksum: %s == %02x\n", $orig, $sum);