/[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

Contents of /protocol/calc.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (show annotations)
Sun Apr 22 22:39:33 2007 UTC (17 years ago) by dpavlin
File MIME type: text/plain
File size: 571 byte(s)
a try at calculating checksum. It seems it's xor
1 #!/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";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26