in reply to CRC32 program logic problem
The following modification of your my_crc function produces the same CRC 32 as String::CRC32.
sub my_crc { # Within each byte the bits are read LSB to MSB # A quirk of Ethernet CRC32 foreach (@msg) { push(@bin_msg, reverse split(//, sprintf('%08b', ord($_)))); } # Augment the message buffer so all message bits # will be shifted out of the remainder push(@bin_msg, (0)x32); # Invert the first 32 bits of the augmented buffer # Another quirk of the Ethernet CRC 32 $bin_msg[$_] ^= 1 for(0..31); print "\n"; while (@bin_msg) { my $bit = shift(@bin_msg); print "bit: $bit\t\t"; push(@crc, $bit); # shift the remainder and subtract the generator if # the bit shifted off was a 1 if (shift(@crc) == 1) { for (my $i = 0; $i < 32; $i++) { if ($gen[$i] == 1) { $crc[$i] ^= 1; } } } print @crc, "\n"; } # Reverse the remainder: another quirk of Ethernet CRC32 @crc = reverse @crc; # Invert the remainder: another quirk of Ethernet CRC32 $crc[$_] ^= 1 for(0..31); }
|
|---|