local CRC = {} function CRC:table() if self._table == nil then local aTable = {} local mod = bit.mod local xor = bit.bxor local rshift = bit.rshift for anIndex = 0, 255 do local aValue = anIndex for _ = 1, 8 do if mod( aValue, 2 ) == 1 then aValue = xor( 0xEDB88320, rshift( aValue, 1 ) ) else aValue = rshift( aValue, 1 ) end end aTable[ anIndex ] = aValue end self._table = aTable end return self._table end function CRC:hash( aValue, aStart, anEnd ) local aTable = self:table() local anHash = 0xFFFFFFFF local band = bit.band local xor = bit.bxor local rshift = bit.rshift for anIndex = ( aStart or 1 ), ( anEnd or aValue:len() ) do anHash = xor( aTable[ band( xor( anHash, aValue:byte( anIndex ) ), 255 ) ], rshift( anHash, 8 ) ) end return xor( anHash, 0xFFFFFFFF ) end