#! /usr/bin/perl use strict; use warnings; # calculate CRC32 sub crc32 { my $bytes = shift; # array reference my @tab = ( 0x77073096, 0xEE0E612C, 0x076DC419, 0x0EDB8832, 0x1DB71064, 0x3B6E20C8, 0x76DC4190, 0xEDB88320 ); my $crc = 0xFFFFFFFF; for (my $i = 0; $i < @{$bytes}; ++$i) { my $val = $crc ^ @{$bytes}[$i]; $crc >>= 8; for (my $b = 0; $b < 8; ++$b) { if ($val & 1 << $b) { $crc ^= $tab[$b]; } } } $crc ^= 0xFFFFFFFF; $crc = [ $crc & 0xFF, $crc >> 8 & 0xFF, $crc >> 16 & 0xFF, $crc >> 24 & 0xFF ]; return $crc; # array reference } 1;