math - One-to-one integer mapping function -


We are using MySQL and developing an application where we do not see the ID sequence publicly. ... ID is hardly top secret and there is no important issue if someone was actually able to decode them.

So, a hash is definitely a clear solution, we are currently using MD5 ... go into 32 bit integers, and we trim from MD5 to 64 bit And then store it. However, we do not know when you trim like this (especially since all numbers come from automatic or official times), how likely is a collision? We currently investigate the collision, but since we once put 100% rows of performance, the performance is terrible (not bulk).

But in the end, we do not really need security, hash and they consume unnecessary space and an additional index is also required ... So there is no simple and good enough work / Is the algorithm which guarantees one-by-one mapping for any number without a clear visual pattern of sequential numbers? / P>

EDIT: I am using PHP which does not support integer arithmetic by default, but after looking around I came to know that this bitwise can be replicated cheaply with operators. Code for 32 bit integer multiplication can be found here:

You can simply do xorax with 0XDEADBEEF, if it is quite good.

Alternatively, multiply by a weird number 2 2 ^ 32. For inverse mapping, multiply by

example only: n = 2345678901; Quantitative Inverse (Mod 2 ^ 32): 2313902621 For Mapping, multiply by just 2345678901 (Mod 2 ^ 32):

1 - & gt; 2345678901 2 - & gt; 396390506

For inverse mapping, multiply by 2313902621.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -