NickGribble has asked for the wisdom of the Perl Monks concerning the following question:
I'm sent data files that have CRC32Q validation on each line. I wrote a script to check each line and it used to give the same value as the checksum in the file but now it doesn't and the code hasn't been changed. Checking the data online shows that the CRC in the file is correct so it's clearly my code that's wrong, but where? In this snippet I've created a page to check that the basic code is correct for just one line. The checksum should be 0x19F112C6 but I'm getting 0x1D094D45. Many thanks.
#!/usr/bin/perl -w use CGI ':standard'; use CGI::Carp qw(fatalsToBrowser); use Digest::CRC; use strict; my $dataToCheck = 'EGCJOBSTHANGAR534712.29N0011243.02W65.26214.10N4520 +18.84432555.4217.0255.84100503/03/2015'; my $crcOnFile = '19F112C6'; my $ctx = Digest::CRC -> new( width => 32, poly => 0x814141AB, refin = +> 0, refout => 0, xorout => 0, init => 0 ); # Convert $dataToCheck to hex. $dataToCheck =~ s/(.)/sprintf("%X",ord($1))/eg; $ctx -> add( $dataToCheck ); my $crc = uc( $ctx -> hexdigest ); print "Content-type: text/html \n\n"; print '<html><body>'; print "Calculated value = $crc, correct value = $crcOnFile"; print '</body></html>';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Digest::CRC giving unexpected result
by NickGribble (Initiate) on Nov 30, 2016 at 13:35 UTC | |
by AnomalousMonk (Archbishop) on Nov 30, 2016 at 14:28 UTC |