【问题标题】:How do I generate a unique hash for different permutations of a string?如何为字符串的不同排列生成唯一哈希?
【发布时间】:2015-05-22 03:40:10
【问题描述】:

如果我将字母表中的每个字母分配给不同的素数并使用字母的乘积,我将得到一个哈希函数,告诉我“abc”与“cba”相同。

我可以使用什么哈希函数使“abc”与“cba”不同?

【问题讨论】:

    标签: string hash hashmap permutation


    【解决方案1】:

    最好的办法是坚持现有的哈希算法,例如 SHA-256

    byte[] strBytes = System.Text.Encoding.UTF8.GetBytes(str);
    byte[] hash = System.Security.Cryptography.SHA256.Create().ComputeHash(strBytes);
    

    这将计算您输入的每个字符串的唯一哈希值。

    旁注:可能有交集(2 个字符串等于同一个哈希),但非常极不可能!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-07
      • 2015-01-06
      • 2011-09-01
      • 1970-01-01
      • 2016-12-19
      • 1970-01-01
      • 2013-09-17
      • 2012-03-07
      相关资源
      最近更新 更多