Question

I have a string, 20-30 characters long, contains case sensitive letters and numbers

I need to generate a 2 chars checksum (in cased sensitive letters and numbers as well)

and put them together for an unique id

What is the fastest method in C# to calculate a checksum for verification purpose?

Was it helpful?

Solution

You have three problems:

  1. Fast checksum calculation for a string: Adler32 is fast enough with good enough distribution for it's speed.

  2. Converting checksum into a string of your character set (case sensitive letters + numbers): If you could add + and / characters, you could easily use base64

  3. Generating a unique ID from those two: This is just impossible with given method. Because you'll end up with same checksum for same string, which doesn't help uniqueness.

What you can do there is to use a global counter if your item set is limited and increment it everytime you create a new record.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top