【问题标题】:How to hash a set of integers, such that we can use the hash to test if a given integer was in the original set?如何散列一组整数,以便我们可以使用散列来测试给定整数是否在原始集合中?
【发布时间】:2017-11-04 19:14:30
【问题描述】:

假设我们有一组整数。有没有办法将它们散列成一个值,这样,只使用散列,我们就可以测试给定的数字是否在原始集合中?

我追求的是一种零知识证明,我可以在不知道原始集合是什么的情况下证明一个数字属于原始集合。

// hash a set of integers 
int Hash(Set<int> values) { ... }

// return true, iff n was in the 
// original set that formed the hash
int Test(int hash, int n) { ... }

// given a set of integers..
Set<int> theSet = {1,4,5,7};

// is it possible to create a "hash"..
int theHash = Hash(theSet);    

// such that, using only the hash, we can test 
// if a number was in the original set?
AssertTrue(Test(theHash, 4));
AssertFalse(Test(theHash, 6));

【问题讨论】:

标签: hash encoding number-theory


【解决方案1】:

从数学上讲,没有办法做到这一点。可以这样想:(32 位)整数的可能集合的数量是 2232,因为每个整数要么会在集合中,要么不会在集合中,并且可能的 32 位整数的数量是 232。整数集太多,无法为每个整数生成唯一代码。

为了使此设置在数学上可行,您需要确保只有 232 个可能的整数集供您使用。如果您只有 32 个可能的整数值,那么这是可能的,因为可能的整数集的数量与可能的 32 位整数的数量完全匹配。您可以通过将您的集合编码为 32 位位向量来完成此操作,每个位指示特定元素是否存在。

【讨论】:

    猜你喜欢
    • 2014-08-15
    • 1970-01-01
    • 1970-01-01
    • 2016-01-27
    • 2021-06-17
    • 1970-01-01
    • 2011-07-26
    • 2010-10-14
    • 2014-10-29
    相关资源
    最近更新 更多