I'm having some problems calculating a checksum for a DNP3 link using Digest::CRC.
The spec says it's a 2 octet CRC based on the polynomial X^16 + X^13 + X^12 + X^11 + X^10 + X^8 + X^6 + X^5 + X^2 + 1. It's also inverted and put in the data block LSB first.
With Perl's Digest package, I set up the algorithm as:
my $ctx = Digest::CRC->new(width=>16, init=>0, xorout=>0xffff, refin=>1, refout=>1, poly=>0x3d65, cont=>0xea82); $ctx->add(0x05); $ctx->add(0x64); $ctx->add(0x05); $ctx->add(0xF2); $ctx->add(0x01); $ctx->add(0x00); $ctx->add(0x00); $ctx->add(0x00); my $x=$ctx->digest; printf("x=%04x\n",$x);
The example in the spec shown for the header: 05 64 05 F2 01 00 00 00 the checksum should be 52 0C. I get x=91fc. I've tried playing with all the parameters but can't seem to get it to come out. Any suggestions?

In reply to Using Digest::CRC to calculate DNP3 checksums by wdtj

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.