I need to implement this algorithm in Node.js, but after searching everywhere I can't find an implementation.


My first approach was reviewed by a member of StackOverflow and was considered correct:

However, it didn't work with the test vectors. So at this point I am assuming that I missed or miss interpreted something and that I implemented the wrong algorithm.


  1. Where can I find an implementation of CRC-16-IBM, Reversed 0xA001, Little Endian (DCBA) ?
  2. Is there a way to know given N test vectors which algorithm is being used to create the CRC?

PS: if it is in Javascript, perfect, if not, I can convert it.

Test message:


CRC for this message:


  • $\begingroup$ The relation to crypto is so thin as to be invisible.. $\endgroup$
    – fgrieu
    Jul 16, 2018 at 10:56
  • $\begingroup$ I thought that CRC16 was a crypto checksum (searchsecurity.techtarget.com/definition/cryptographic-checksum). Am I mistaken? $\endgroup$ Jul 16, 2018 at 11:21
  • $\begingroup$ I'm putting this question on hold as off-topic because it is not about cryptography as defined in our help center. As a heads-up: Cyclic Redundancy Check codes are used for error-detection and correction. They are not related to cryptography because CRCs are easily reversible functions... in contrast to (for example) cryptographic hash functions (like SHA-256). $\endgroup$
    – e-sushi
    Jul 16, 2018 at 12:44
  • $\begingroup$ @Flame_Phoenix: as a rule, if the whole difficulty preventing computing the right value is the algorithm, then it is not cryptography. In cryptography-as-a-science, ever since Kerchoff's principle (actually the second principle in the original French text of 1883), there's always a key, and it always has a secret component. $\endgroup$
    – fgrieu
    Jul 16, 2018 at 13:00
  • $\begingroup$ @fgrieu Ah, so if my problem doesn't include a key, I should not post it here, correct? Thanks for explaining ! $\endgroup$ Jul 16, 2018 at 13:02

1 Answer 1


The CRC-16 polynomial 0xCD83 will produce the byte-swapped checksum of your data. It is implemented in the following C++ routine:

uint16_t crc16(uint16_t state, uint8_t byte) {
  uint16_t mask;
  uint16_t crc = state ^ uint16_t(byte);
  for (int j = 7; j >= 0; j--) {
    mask = -(crc & uint16_t(1));
    crc = (crc >> 1) ^ (mask & uint16_t(0xCD83));
  return crc;

If you initialize state=0 and feed this routine your test vector

state = crc(state, data[i]);

Then after processing the state will equal 0xC58D which is the byte-swapped checksum that you wanted.

There is no 16-bit polynomial that will produce the checksum with the other byte ordering (0x8DC5).

  • $\begingroup$ Since according to @e-sushi, CRCs are easily reversible, is there a way, that given any test vector, to find out the CRC algorithm used to compute it? $\endgroup$ Jul 16, 2018 at 13:02
  • $\begingroup$ @Flame_Phoenix: Yes: Berlekamp-Massey. If we only care about specific length(s) of messages; there's a different method working for any affine transformation (including CRCs with whatever bogus byte order and variant the implementor may have used). $\endgroup$
    – fgrieu
    Jul 16, 2018 at 13:13
  • $\begingroup$ This answer is wrong for two reasons: First you included the expected CRC into the message. Second: With your construction you cannot reproduce the expected CRC for the other given test vector. I did not found any CRC-16 algorithm which can do this. $\endgroup$ Jul 16, 2018 at 14:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.