jenssegers / optimus

🤖 Id obfuscation based on Knuth's multiplicative hashing method for PHP.
https://jenssegers.com
MIT License
1.27k stars 74 forks source link

How unique is unique #27

Closed ivanvermeyen closed 7 years ago

ivanvermeyen commented 7 years ago

Hi,

I've been looking for a decent, basic explanation about hashing, but it's a bit hard to find. I know that generating random values will always have a chance to return duplicate results. MD5 hashes, for example are also random, but not unique...

My big question is if this also applies to the method of hashing that you use. Will there be even the slightest chance that the resulting hash of value X will be the same as the hash of value Y?

Is there a certain rule behind this idea? Is there a requirement of the amount of possible character combinations used for the resulting hash (like hashids uses a pool of characters instead of just numbers) versus the number of characters in the original value?

Or should I always check the database for duplicates?

I hope someone can shine a light on this for me... :)

jenssegers commented 7 years ago

Everything integer lower than 2147483647 will be mapped to a different integer based on your prime number. Collisions within this range are not possible.

jenssegers commented 7 years ago

I'm looking into making this maximum number configurable so that you can generate smaller or nigger numbers, but no luck yet.

ivanvermeyen commented 7 years ago

Ok, thanks for the quick reply 👍

hashimaziz1 commented 2 years ago

I'm looking into making this maximum number configurable so that you can generate smaller or nigger numbers, but no luck yet.

Lol that is a very unfortunate typo