Hi All,
I am having some trouble figuring out how table-based CRC works, and hope that someone can point out where I am going wrong. Lets start by defining a few things:
Message: 1101011011 Polynomial: x^4 + x^1 + 1 (ie 10011) Augmented Message: 11010110110000 (add 'W' = 4 zeros) Padded Message: 0011010110110000 (extend to 16-bits)
These numbers may be familiar to some, as they are taken from the "Painless Guide to CRC Error Detection Algorithms". Now, lets start by working through the problem by hand. Note that '^' represents the XOR operation:
0011010110110000 ^ 10011 0001001110110000 ^ 10011 0000000010110000 ^ 10011 0000000000101000 ^ 10011 0000000000001110Which gives the expected '1110' checksum. It is fairly trivial to write code that will perform this sort of bit-by-bit CRC generation. However, if we want to speed things up, we need to be able to work with more than a single bit at a time. It would be nice to be able to process the message byte-by-byte. This may be done using the following algorithm (again taken from the guide):
Algorithm
---------
- Shift the register left by one byte, reading in a new message byte.
- Use the top byte just rotated out of the register to index the table of 256 8-bit values.
- XOR the table value into the register.
- Goto 1 iff more augmented message bytes.
Now, as far as I understand it, the table index corresponds to every possible message byte (ie 2^8 combinations of bits). The table entry at a particular index contains the XOR sum of the polynomial offset according to the table index. For example, at table index '00110101' (the first byte of the padded message), the table entry would be:
00110101 Table index -------- 10011 | ^ 10011 | Only this bit gets XOR'ed together, ie ^ 10011 | do not include the index. ^ 10011 | -------- 00110000 Table entryHowever, if you work through the algorithm with this table entry, you do not end up with the correct checksum. Now, I have tried all sorts of weird and wonderful combinations to try and get it to work, with no success. For example, I thought that you might need to include the index in the XOR calculation that is used to fill the table - however this did not work either.
Given that its apparent what the algorithm is trying to do when you look at the hand worked example at the top of this post, I am somewhat alarmed by my inability to figure out what I am doing wrong. Can anyone spot the problem?
- S