-1

For a human-friendly "checksum" value I like to generate values in the range of 0 to 99 only.

The input is a string of ASCII chars (mainly a-z and 0-9).

I figure I should use some kind of CRC algorithm for this, but I wonder how I get the best result with a well balanced checksum result.

The cheapest technique I can imagine is to calculate a CRC-16 or CRC-32 and then taking the result modulo 100. But that's not giving a good result, is it?

Ideally, what would be a good (CRC-like) algorithm for checksumming a string of values out of a set of N different values (e.g. N = 36 if I use only a-z and 0-9), resulting in a checksum range of 0 to M-1?

It doesn't have to be fast as I'm dealing with small strings.

Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149

1 Answers1

1

A cyclic redundancy check can be done with any number of output bits, so you could just use something like CRC-8 to get values from 0 to 255 (which you can represent in two hexadecimal characters). See the wikipedia link for more information about CRCs.

As for taking a CRC-32 modulo 100 not giving good results, this depends on what you consider "good". For just 100 hash values, collisions are bound to occur frequently anyway, so you need to weigh hash length against risk of collisions.

Jordi Vermeulen
  • 1,168
  • 1
  • 10
  • 17