Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Using Digest::CRC to calculate DNP3 checksumsby dasgar (Priest) |
on Sep 08, 2016 at 05:34 UTC ( [id://1171362]=note: print w/replies, xml ) | Need Help?? |
I thought I'd challenge myself to see if I could figure this out. As I started looking into CRC algorithms, I quickly found myself in over my head. But I think that I was actually able to figure it out. Looking at the source code of Digest::CRC, I took a guess that the value for 'const' should be 0 instead of '0xea82'. That got me closer for ASCII input. Combining that with the suggestion from the Anonymous Monk got me closer for hex input. In both cases what I mean by getting closer is that I got the right characters, but in the wrong order. Basically, I needed to reverse the output by bits. For example, with your sample header, I was getting 'c52' instead of '520c'. The two bits here are '0c' and '52'. Reversing the two bits of 'c52' (or '0c52') produces '520c'. In searching for references for CRC-DNP checksums, I found an online checksum calculator (found here). I used it to 'verify' the output of the following code.
That produced the following output:
I've tried a few other examples to compare the output of my code versus the online calculator and I'm getting the same values for the CRC-DNP checksums. Perhaps more knowledgeable monks might be able to identify issues with my code, but I think it should help you get further along with what you're trying to do. UPDATE: Since the OP was cross posted, I cross posted this response (see here) as well to the same site.
In Section
Seekers of Perl Wisdom
|
|