Checksum without logic/bitwise operations

473 views Asked by At

I need to calculate a 1 byte checksum over 15 bytes. My first idea was to use something like crc8, but the problem is that I have to use a really limited BASIC interpreter which only supports basic arithmetic operations (+-*/) but no bitwise "xor", "and" or "or" and no "shift" operations.

So my question is: is it possible to calculate a somewhat reasonable checksum with these limitations? I think calculating the sum would be a poor solution, but I can't think of something else at the moment.

2

There are 2 answers

0
Mark Adler On BEST ANSWER
LET a = 1
LET b = 0
FOR n = 1 to 15
   LET a = a + c(n)
   LET b = b + a
NEXT n
LET b = mod(b, 251)

Then use b as the check value. The advantage of this over a simple sum is that it is not commutative. The order of the bytes matter. Also a string of zeroes does not give you zero, and the check value depends on how many zeros.

2
mcdowella On

If you have truncating integer division you can define mod(a, b) = a - (a/b) * b, which is pretty much all you need for http://en.wikipedia.org/wiki/Adler-32.