Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function adler32(input)
- local a = 1
- local b = 0
- for i=1, #input do
- a = (a + input[i]) % 65521
- b = (b + a) % 65521
- end
- return (b * 65536) + a
- end
- function fletcher32(input)
- local a,b = 0, 0
- for i=1, #input, 2 do
- a = (a + (input[i]*256) + input[i+1]) % 65535
- b = (b + a) % 65535
- end
- return (b * 65536) + a
- end
- function crc16(input) -- poly = 0x1021 (CRC-16-CCITT)
- local rem = 0
- for i=1, #input do
- rem = bit.bxor(rem, bit.blshift(input[i], 8))
- for j=1, 8 do
- rem = bit.blshift(rem, 1)
- if bit.band(rem, 0x8000) > 0 then
- rem = bit.bxor(rem, 0x1021)
- end
- rem = bit.band(rem, 0xFFFF)
- end
- end
- return rem
- end
- function crc32(input) -- poly = 0x04C11DB7 (CRC-32)
- local rem = 0
- for i=1, #input do
- rem = bit.bxor(rem, bit.blshift(input[i], 24))
- for j=1, 8 do
- rem = bit.blshift(rem, 1)
- if bit.band(rem, 0x80000000) > 0 then
- rem = bit.bxor(rem, 0x04C11DB7)
- end
- rem = bit.band(rem, 0xFFFFFFFF)
- end
- end
- return rem
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement