从无序的任意字符串中创建一个固定长度的确定性哈希

发布于 2025-02-08 03:26:25 字数 539 浏览 2 评论 0原文

我正在尝试提出一种校验和算法,该算法基于未订购的任意字符串产生固定长度的哈希。

我的意思是说,字符串的哈希[“ a”,“ b”]应该导致与[“ B”,“ A”] 。另外,[“这是一个非常长的字符串”,“”应该导致['a“”,“这是一个非常长的字符串”]

理想情况下,我希望看起来像SHA256字符串相似的东西,但这并不重要。

哈希不需要唯一,但是确实需要充当校验和,因此,对于大量输入,至少应该有些不太可能会碰撞。

正如我说的那样,这是一个校验和密码哈希,因此可以进行某种程度的重复。

伪代码在键入时在语法上没有其他原因写的伪代码是:

func hash(inputs []string) string

一种选择是简单地订购输入并从中创建SHA256,但这是记忆密集型的。另一个选择是使用V5 UUID转换为UUID,然后将其XOR,但理想情况下,算法不需要其他哈希功能。

任何想法都将不胜感激。

I am trying to come up with a checksum algorithm that produces a hash of fixed length based on arbitrary strings that are un-ordered.

By that I mean to say, the hash of the strings ["a", "b"] should result in the same hash as ["b", "a"]. Also, ["this is a really long string", "a"] should result in the same as ["a", "this is a really long string"].

Ideally, I would like this hash to look something similar to a sha256 string, but that is less important.

The hash doesn't need to be unique, but it does need to act as a checksum, so for lots of inputs, it should be at least a bit unlikely that you'd get collisions.

As I say, this is a checksum rather than a cryptographic hash, so some degree of duplication is ok.

The pseudocode, written in go for no other reason than it's syntactically light whilst being typed, would be:

func hash(inputs []string) string

One option would be to simply order the inputs and create a sha256 from it, but that is memory intensive. Another option is to convert to uuid using a v5 uuid, and XOR it, but ideally the algorithm would require no other hashing function.

Any thoughts would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人如初 2025-02-15 03:26:25

选择适合您需要的哈希算法,然后将其应用于每个元素。然后将所有哈希都放在一起。这将为您带来相同的结果,而与元素的顺序无关。

Chose a hash algorithm that suits you need, and apply it on each element .. and then xor all the hash's together. This will give you the same result, independent of the sequence of the elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文