开发者

CRC test vectors for CRC16 (CCITT)

Does anyone know of some CRC test vectors for CRC16-CCITT?

I do not have a CRC implementation I can trust and either need to test someone's implementation or my own. (For CRC32, I use the PNG code as the gold standard, as it's a reputable reference implementation.)

(this site's CRC calculator looks useful but I need to verify correctness somehow)


UPDATE: The above CRC calculator looks useful 开发者_如何学运维but it takes only ascii, no way to enter hex. --- it's very awkward to enter hex input, though. (ASCII 12 in hex can be entered as %31%32, so you can't just copy+paste a long string of hexadecimal bytes; also the % character doesn't seem to have an escape)

I have verified this online calculator, which takes hex inputs, against the Boost test vectors for CRC16, CRC16-CCITT, and CRC32.


Boost has a nice CRC implementation you can test against. As far as I know it's possible to configure it for CRC16. http://www.boost.org/doc/libs/1_41_0/libs/crc/index.html

There seems to be an example of how to set it up to simulate CCITT on this page: http://www.boost.org/doc/libs/1_41_0/libs/crc/crc.html


Python's binascii package has had CRC-16 for a while.

Use binascii.crc_hqx(val, 0xFFFF) - the previous example are...

$ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import binascii
>>> tv = binascii.a2b_hex("12345670")
>>> hex(binascii.crc_hqx(tv, 0xFFFF))
'0xb1e4'
>>> tv = "123456789".encode("ascii")
>>> hex(binascii.crc_hqx(tv, 0xFFFF))
'0x29b1'


Here are two test vectors for CCITT-16 CRC (whose polynomial is X16 + X12 + X5 + 1 (0x1021 in big-endian hex representation); initial CRC value is 0xFFFF. XOR value out is zero.) are:

0x12345670 = 0xB1E4

0x5A261977 = 0x1AAD


I've found this one:

http://introcs.cs.princeton.edu/java/51data/CRC16CCITT.java.html

"123456789".getBytes("ASCII"); -> 0x29b1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜