2

Basically I have 24 digit hexadecimal id values. I need a function that can take one of these ids and turn it into a 10 digit decimal value. It does not need to be cryptographically secure. I just need to ensure that the same input will always get the same output, and that the resulting value has as low of a chance as possible to be the same with different inputs.

chrispytoes
  • 1,714
  • 1
  • 20
  • 53
  • 3
    Without knowing something about the distribution of those hexadecimal ID values, we can't suggest anything with a lower chance of duplicates than just converting from hex to decimal and taking the last ten digits. – ruakh Mar 24 '17 at 18:37
  • See also: [smaller hash from a standard hash](http://stackoverflow.com/a/32913069/3789665). – greybeard Mar 25 '17 at 00:41

1 Answers1

2

Something like this should work as you are asking -

shorterHash := MD5(hexId) # 16 byte
return shortedHash.substring(0, 10) # this is still non-colliding enough 

I hope there are many standard implementations of MD5 on your language on internet.

Kaidul
  • 15,409
  • 15
  • 81
  • 150