Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CRC = {}
- local xor = bit.bxor
- local rshift = bit.brshift
- local band = bit.band
- function CRC.table()
- if CRC._table == nil then
- local tab = {}
- for i = 0, 255 do
- local v = i
- for _ = 1, 8 do
- if v % 2 == 1 then
- v = xor(0xEDB88320, rshift(v, 1))
- else
- v = rshift(v, 1)
- end
- end
- tab[i] = v
- end
- CRC._table = tab
- end
- return CRC._table
- end
- function CRC.hash(v)
- local tab = CRC.table()
- local hash = 0xFFFFFFFF
- for i = 1, #v do
- hash = xor(tab[band(xor(hash, v:byte(i)), 0xFF)], rshift(hash, 8))
- end
- return xor(hash, 0xFFFFFFFF)
- end
- return CRC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement