Hi

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>';

In reply to Digest::CRC giving unexpected result by NickGribble

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.