Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formula for Unique Hash from Integer Pair

Tags:

hash

I think I can use Cantor's to create a unique hash n = ((x + y)*(x + y) + x - y)/2...

but can I reverse this hash? And if not, can someone provide a similar formula pair for a reversible hash?

Thanks.

like image 923
Jeff Avatar asked Feb 05 '26 07:02

Jeff


1 Answers

if x and y and n are all the same data types.

n = ((x + y)*(x + y) + x - y)/2...

when x and y are near the datatype::max n will overflow and you will lose information and not be able to recover x and y.

If on the other hand if x and y are always within a range let say 0-FOO

n = Foo * x + y 

can be a recoverable hash provided again n has not overflown

   n % Foo

will give you y. Once y is known (n-y)/Foo will give you x

like image 162
parapura rajkumar Avatar answered Feb 09 '26 09:02

parapura rajkumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!