1 |
dpavlin |
11 |
#!/usr/bin/perl -w |
2 |
|
|
|
3 |
|
|
# calc.pl |
4 |
|
|
# |
5 |
|
|
# 04/22/07 14:29:00 CEST Dobrica Pavlinusic <dpavlin@rot13.org> |
6 |
|
|
|
7 |
|
|
use strict; |
8 |
|
|
use File::Slurp; |
9 |
|
|
|
10 |
|
|
my $file = shift @ARGV || die "usage: $0 packet\n"; |
11 |
|
|
|
12 |
|
|
my $p = read_file( $file ) || die "can't read $file: $!"; |
13 |
|
|
|
14 |
|
|
my $orig = $2 if ( $p =~ s/(\r\n)(\w+)$/$1/s ); |
15 |
|
|
|
16 |
|
|
print "ORIGINAL checksum: $orig\n"; |
17 |
|
|
|
18 |
|
|
my $sum = 0; |
19 |
|
|
for my $i ( 0 .. length($p) ) { |
20 |
|
|
my $c = substr($p,$i,1); |
21 |
|
|
my $o = ord($c); |
22 |
|
|
my $h = sprintf('%x',$o); |
23 |
|
|
# $sum += $o; |
24 |
|
|
$sum ^= $o; |
25 |
|
|
print "# $i '$c' $o 0x$h -- $sum 0x", sprintf('%x',$sum),"\n"; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
print "ORIGINAL checksum: $orig\n"; |