hex-in / libscrc

libscrc is a library for calculating CRC3 CRC4 CRC5 CRC6 CRC7 CRC8 CRC10 CRC11 CRC12 CRC15 CRC16 CRC24 CRC30 CRC31 CRC32 CRC64 CRC82
GNU General Public License v3.0
49 stars 13 forks source link

Update _crc16module.c #12

Closed Tobi823 closed 1 year ago

Tobi823 commented 1 year ago

Thanks for your hard work. Your library helped me a lot and it much faster than my own C code :)

I spot a small error in the documentation for CRC-16/DNP.

According to this https://reveng.sourceforge.io/crc-catalogue/16.htm it should be Refin=True Refout=True. And it seems that libscrc.dnp already uses refin and refout.

import libscrc
import numpy as np

b1 = 0x82
b2 = 0xea

data = np.array([0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, b1, b2], np.uint8)

# width=16 poly=0x3d65 init=0x0000 refin=true refout=true xorout=0xffff check=0xea82 residue=0x66c5 name="CRC-16/DNP"
val1 = libscrc.dnp(data)
val2 = libscrc.hacker16(data, poly=0x3d65, init=0x0000, refin=True, refout=True, xorout=0xffff, reinit=False)

print((val1 ^ 0xffff) == 0x66c5) # is True
print(val1 == val2) # is True