Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^5: How to use perl digest module to calculate CRC?

by BrowserUk (Pope)
on Mar 21, 2013 at 14:35 UTC ( #1024764=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024764]
[LanX]: ah... Denmark is planning to build a wall at the German border!
[LanX]: # Pestis Africana Suum
[erix]: that's an old plan, I think. Isn't there already a danewal (or some such name)?
[marto]: Build with -Wall
[erix]: Danewerk
[LanX]: I seem to remember that the danewall was build by the Frankish empire against the Danes
[erix]: 500 AD thru viking age

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2018-03-22 18:38 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (283 votes). Check out past polls.