looking for a checksum routine in C

A

Angelo Chen

Hi,

I'm looking for a way to calculate a checksum for a block of memory,
I'd like to use a readable two char(0..9, A..Z) to represent this
checksum, so the checksum should be less than 1296. I'm looking at
crc8, its result is 8 bits, that's only 256, crc16's result is 65535,
that's more than what the two char can accommodate, any idea how to
achieve this? even less than 1296, 1024 will do.

Thanks,

Angelo
 
R

Richard Bos

Angelo Chen said:
I'm looking for a way to calculate a checksum for a block of memory,
I'd like to use a readable two char(0..9, A..Z) to represent this
checksum, so the checksum should be less than 1296. I'm looking at
crc8, its result is 8 bits, that's only 256, crc16's result is 65535,
that's more than what the two char can accommodate, any idea how to
achieve this? even less than 1296, 1024 will do.

So what you want is basically a CRC-10, and the quality won't need to be
fabulously high since, with those specs, you're not going to share your
CRCs with anybody else.

I strongly suspect a websearch on CRC-10 would be helpful to you.

Richard
 
T

Thad Smith

Angelo said:
I'm looking for a way to calculate a checksum for a block of memory,
I'd like to use a readable two char(0..9, A..Z) to represent this
checksum, so the checksum should be less than 1296. I'm looking at
crc8, its result is 8 bits, that's only 256, crc16's result is 65535,
that's more than what the two char can accommodate, any idea how to
achieve this? even less than 1296, 1024 will do.

I would use a 16- or 32-bit CRC and then reduce mod 1296.
 
A

Angelo Chen

I would use a 16- or 32-bit CRC and then reduce mod 1296.

That's one solution, but Richard suggests crc10, that's a good
approach too, I'm still searching for any sample code, so far, none
working code turned out.
 
V

viza

I would use a 16- or 32-bit CRC and then reduce mod 1296.

Not necessarily very safe. You would need to investigate the type of CRC
to see that it didn't, eg, treat the data as words and so using modulo
(especially modulo a non-prime with only two bits set) might discard all
information about certain bits in each input word.
 
A

Angelo Chen

#define BASE32 "0123456789ABCDEFGHIJKLMNOPQRSTUV"
{
  char str[2];
  int crc= crc10( data );

  str[0]= BASE32[ crc & 0x1f ];
  str[1]= BASE32[ crc >> 5 ];

}

thanks, that finally solves the problem. case closed:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top