英文:
Hash function for string tree path
问题
我有一棵树,其中包含节点和连接。一个节点可以有多个子节点,而且树是非循环的。每个节点从根节点到该节点都只有一条路径。
对于独特的遍历路径,我正在生成一个称为“路径(PATH)”的字符串。它是一个由节点名称和顺序(从左到右)组成的字符串。公式为(节点名称 - 顺序 - 当前节点)
路径确保了唯一性。对于给定的字符串,我想要生成一个唯一的32位字母数字串。如何做到这一点,有什么适合的哈希函数呢?
类似于:
function( N1-1-N2-3-N5 ) = 'HNLKJHDSVX6790978767098' // 32位字符
它应该对相同的输入输出相同的哈希值。这不需要用于安全性,只用于碰撞检测。
英文:
I have a tree that has nodes and connections. One node can have multiple children and the tree is not cyclic. Each node will have only one travel path from the root to the node .
For the unique traversal path in am generating a string called a PATH. It's a string node name plus order ( left to right ). The formula is ( node name - order - current node )
Path ensures the uniqueness. For the given string i want to generate a unique 32 alphanumeric. How to do that, what is a suitable hash function?
Something like
function( N1-1-N2-3-N5 ) = 'HNLKJHDSVX6790978767098' // 32 digit
It should output the same hash for the same input. It's not required for security, just for collision detection.
答案1
得分: 2
MD5,在密码学上来说已经被破解,但作为一个简单的哈希函数仍然可行,这就是为什么我认为它会适合你。只需继续使用十六进制表示法进行哈希运算,你就可以得到32字节的哈希值。
在这里查看
> MD5(消息摘要)算法是广泛使用的密码哈希函数,生成128位(16字节)的哈希值,通常以文本格式表示为32位十六进制数字。
英文:
MD5, which, cryptographically speaking, is broken, is still viable as a simple hash function, which is why I think it will suit your fancy. Just stick with the hexadecimal notation for the hash function and you should have your 32 byte hash.
Take a look here
> The MD5 (Message Digest) algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论