Re: Better verification: checksum vs. xor

On 24 Dec, 10:35, Willem <wil...@xxxxxxxx> wrote:
James Harris wrote:

) On 24 Dec, 09:56, p...@xxxxxxxxxxxxxxxxx (Pascal J. Bourguignon)) wrote:

) ...
)> > There is no transmission. This will be a block of data in memory. At
)> > the beginning of the block will be an unknown number of garbage bytes
)> > which need to be skipped.
)> > All values should be 8-bit only.
)> Do you realize that this is an entirely different problem?
) Really? In what respect?

How many 'unknown garbage bytes' will have to be skipped ?

For example, for 10 garbage bytes that means that 10 checksums must
(correctly) fail.  If you have an 8-bit checksum/CRC/xor/whatever then
there is roughly a 1/256 chance that any one of those checks gives
a false positive.

For a mere 10 'unknown garbage bytes' that turns out to be almost
a 4% cumulative chance of a fail (false positive).

Are you still sure you want only 8 bits ?

Very good point but let me repeat some of my original post:

"I am looking for a simple way (usable on a powerful PC or a tiny
microcontroller) to verify a small amount of data of about eight

The code is to look at certain offsets in some data for a header. The
header is to consist of the following fields in sequence.
* a magic value
* the eight bytes of data
* the check value (based on the 8 bytes not including the magic

The magic value will be a number of bytes (as they can be checked
individually). The rest (the data and the check value) will be single
bytes. I'm not happy with using the magic value as the only check for
a valid header hence the need for a check value. Both the magic value
and the check value will need to match.