来自整数对的唯一散列公式 [英] Formula for Unique Hash from Integer Pair

查看:83
本文介绍了来自整数对的唯一散列公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我可以使用Cantor创建一个独特的散列n =((x + y)*(x + y)+ x - y)/ 2 ...

但是我可以逆转这个散列吗?如果没有,有人可以提供类似的公式对可逆的哈希?



谢谢。

解决方案

如果x和y和n都是相同的数据类型。

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

当x和y接近数据类型:: max时,n将溢出,您将失去信息并且无法以恢复x和y。

另一方面,如果x和y总是在一个范围内,比如说0-FOO

  n = Foo * x + y 

可以再次提供可恢复的散列n没有溢出

  n%Foo 

会为您带来 y 。一旦知道 y (n-y)/ Foo 会为您带来 x

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.

解决方案

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

这篇关于来自整数对的唯一散列公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆