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 th开发者_运维知识库e 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?
Using just the two computations of the CRC16, no.
CRC16 is just a checksum: it can tell you that there is a difference, but not where.
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.
精彩评论