http://www.perlmonks.org?node_id=1024764


in reply to Re^4: How to use perl digest module to calculate CRC?
in thread How to use perl digest module to calculate CRC?

I'm acting as a transmitter, and I need to calculate the CRC and then send it along with the message.

Okay. But you still need to ensure that you calculate it in the same way that the receiver does; which means you need the full parameterisation of the algorithm used.

What you've supplied so far is not enough information:

The CRC algorithem that I'm using is not standard. P = 1EDC6F41 Init value = FFFFFFFF

Hm. Looks an awful lot like this.

But without the full parameters, this is only guesswork:

#! perl -slw use strict; use Digest::CRC; my $o = Digest::CRC->new( width => 32, init => 0xffffffff, poly => 0x1edc6f41, xorout => 0xffffffff, refout => 1, refin =>1, cont => 1 ); while( <DATA> ) { my( $addrr, @hexBytes ) = split; my $data = pack 'H*', join '', @hexBytes; $o->add( $data ); } print $o->hexdigest; __END__ @0000 FF FF FF 02 24 E0 02 26 A9 02 21 B0 02 21 53 02 @0010 21 6A 02 21 EE 02 21 F5 02 25 55 02 22 7B 02 23 @0090 D2 AF D2 B8 75 1F 01 12 0B B1 75 15 00 E5 0B 20

Note: You'll probably need $o->digest rather than $o->hexdigest.

NB: But the above will probably fail because it is just guesswork. Also, you'll need to retain the packed data for transmission.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.