I'm looking for an algorithm (or hash, etc...) that can map a fixed length string (15 character) to unique number (5 digits). I expect it to map ABCDEFGHIJKLMNO to 12450 or ONMLKJIHGFEDCBA to 15647 (The generated number must be unique).
Asked
Active
Viewed 351 times
0
Hadi Mohammadi
- 314
- 2
- 5
- 20
-
Just do a 16bit CRC, pad it with 0's or something, https://stackoverflow.com/questions/22860356/how-to-generate-a-crc-16-from-c-sharp – TheGeneral Jun 17 '19 at 06:38
3 Answers
3
it's not possible to map
a fixed length string (15 character)
into a
unique number (5 digits)
because 15 characters with 26 possible characters (A-Z) > than 5 digits with 10 possible digits (0-9)
so 26^15 > 10^5 or 1.677.259.342.285.725.925.376 > 100.000
fubo
- 44,811
- 17
- 103
- 137
1
What you are asking for is impossible.
There are more possible 15 character strings than there are possible 5 digit numbers. Therefore it is impossible to map each string to a unique number.
Greg
- 23,155
- 11
- 57
- 79
0
It is truly impossible to do that. Unless, if you change it into alphanumeric, maybe that could work.
Syafiqur__
- 531
- 7
- 15