将 (3) 个 32 字符十六进制哈希合并为一个唯一的 32 字符哈希?
我有 (3) md5sums,我需要将它们组合成一个散列。新的哈希值应为 32 个字符,但区分大小写,并且可以是任何字母或数字。在 Python 中执行此操作的最佳方法是什么?
I have (3) md5sums that I need to combine into a single hash. The new hash should be 32-characters, but is case-sensitive and can be any letter or number. What's the best way to do this in Python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我首先将 md5 哈希值组合成一个哈希值。您可以使用 SHA256,因为它最终会包含更多字节:
然后您可以使用 base64 使用字母、数字和一些额外符号对其进行编码:
如果您只需要 32 个字符长,请切掉最后的位:
这可以包含
+
和/
除了像你的OP建议的字母和数字之外。如果你想替换它们,可以使用第二个参数进行b64encode:I would start by combinind the md5 hashes into a single hash. You can use SHA256 since it will contain more bytes in the end:
Then you can use base64 to encode it using letters, numbers, and a few extra symbols:
If you want just 32 characters long, slice off the last bits:
This can contain
+
and/
in addition to letters and numbers like your OP suggests. If you want to replace them, you can use the second parameter to b64encode:最简单的方法是将 3 个和组合成一个 96 个字符的字符串,并对其运行 MD5 哈希。
The easiest way would be to combine the 3 sums into a single 96-character string and run an MD5 hash on that.
只是另一种方式,使用“字符”来表示任何 Unicode 代码点,这就是我想到的,包括我的笨手笨脚:
我可能不得不使用每个字符 13 位来避免任何标点符号,但我不想投入时间,因为无论如何你都不关心可逆性。
[后来]不,不必:
Just for yet another way, using "characters" to mean any Unicode codepoint, here's what I came up with, including my bumbling around:
I would probably have had to use 13 bits per character to avoid any punctuation, but I didn't want to invest the time since you didn't care about reversibility anyway.
[later] nope, didn't have to: