Search code examples
bytebit-manipulationcrccrc16

Determine Error Offset Byte by CRC16


Is it possible to determine the byte, or bytes, that have changed from a CRC16 calculation?

For example, say I get a config file that is 780 bytes that includes the CRC16 as a two byte value at the end (so the CRC16 is calculated based on the first 778 bytes). When I calculate the CRC16 for the file contents (the 778 bytes that do not include the CRC16 at the end) and it is different, can I determine the byte offset the error occurred at?


Solution

  • The short answer is NO, you can't.

    To understand why you have to understand how the CRC is computed and that mathematically that is called a hashing operation. What it means is the the output can not be reconstructed reliably from the generated hash code (in this case the CRC).

    There are statistical analysis methods that may allow you to infer some information about the original text based on certain specific input test cases but in the majority of cases, and to a naive observer there's not direct mapping back to the original text from the CRC. So unless the original text was constructed in a certain way there's no way to know the offset at which data was changed in most cases.