Search code examples
javascriptchecksumcrccrc16

How do I implement a CRC16 with a custom polynomial in Javascript?


Background

I need to implement a CRC16 with a custom polynomial in Javascript.

Research

After searching several NPM modules and this SO question ( as well as all the links the comments suggest ):

I am still not any closer to my goal.

Problem

My problem is that even though I have the code, I can't understand how to re-use a given CRC16 solution because I don't know where to find the polynomial definition in the code. With all the shifts and whatnot it's just too cryptic for me.

Question

How can I have a CRC16 function with a custom polynomial ?


Solution

  • The example linked has a table derived from the CRC polynomial. You can certainly find code that generates the table, given the polynomial. You can find code that computes any CRC, and code that generates CRC code, including the table, given the definition of the CRC (polynomial, bit-ordering, initial value, final xor value).