如何获得字符串的 bigint 哈希值
我们有一个字母数字字符串(最多 32 个字符),我们希望将其转换为整数 (bigint)。现在我们正在寻找一种算法来做到这一点。碰撞并不坏(因此我们使用 bigint 来稍微防止这种情况),重要的是,计算出的整数在 bigint 范围内不断分布,并且对于给定字符串,计算出的整数始终相同。
We have an alpha numeric string (up to 32 characters) and we want to transform it to an integer (bigint). Now we're looking for an algorithm to do that. Collision isn't bad (therefor we use an bigint to prevent this a little bit), important thing is, that the calculated integers are constantly distributed over bigint range and the calculated integer is always the same for a given string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此页面有一些。您需要移植到 64 位,但这应该是微不足道的。 SBDM 哈希的 AC# 端口位于此处 。哈希函数的另一页此处
This page has a few. You'll need to port to 64bit, but that should be trivial. A C# port of SBDM hash is here. Another page of hash functions here
大多数编程语言都带有内置构造或标准库调用来执行此操作。如果不懂语言,我认为没有人可以帮助你。
Most programming languages come with a built-in construct or a standard library call to do this. Without knowing the language, I don't think anyone can help you.
是的,“哈希”应该是对我的问题的正确描述。我知道,有CRC32,但它只提供了一个32位整数(在PHP中),并且这个32位整数至少有10个字符长,所以很大范围的整数没有被使用!?
大多数情况下,我们有一个像“PX38IEK”这样的短字符串或一个像“24868d36-a150-11df-8882-d8d385ffc39c”这样的36个字符的UUID,所以字符串是任意的,是的。
它不一定是可逆的(因此碰撞也不错)。字符串转换为什么 int 也并不重要,我唯一的愿望是尽可能最好地使用完整的 bigint 范围。
Yes, a "hash" should be the right description for my problem. I know, that there is CRC32, but it only provides an 32-bit int (in PHP) and this 32-bit integers are at least 10 characters long, so a huge range of integer number is unused!?
Mostly, we have a short string like "PX38IEK" or an 36 character UUID like "24868d36-a150-11df-8882-d8d385ffc39c", so the strings are arbitrary, yes.
It doesn't has to be reversible (so collisions aren't bad). It also doesn't matter what int a string is converted to, my only wish is, that the full bigint range is used as best as possible.