Hash函数
Hash函数 Hash函数,又称单向散列函数,是将任意长的消息映射为定长的Hash值的公开函数。Hash函数在密码学中应用十分广泛,与各种加密算法有着密切的联系。Hash函数的模型如下: h=H(M) 其中,M是待处理的消息;H是Hash函数;h是生成的消息摘要,它的长度是固定的,并且和M的长度无关。 Hash函数具有下面一些性质: (1) Hash函数可应用于任意长度的数据块; (2) Hash函数产生定长的输出; (3)对于任何给定的M和H,计算h比较容易,用硬件和软件均可实现; (4)对任何给定的H和h,无法计算出M,这又可称之为单向性; (5)对任何给定的H和M,找到不同的消息M1,使得H(M1)=拭州,在计算上是不可行的,这又称之为抗弱碰撞性; (6)对任何给定的H,找到不同的消息M1和M2,使得H(M1) = H(M2),在计算上是不可行的,这又称之为抗碰撞性。
Java里的String类的Hash函数是: s31^(n-1)+s31^(n-2)+...+s s*是字符串中的第i个字符;空字符串的Hash值是0
原文: The String class contains a method hashCode() which is used to generate a key which can used as the key for a hash table. The hashcode for a String object is computed as s31^(n-1)+s31^(n-2)+...+s using integer arithmetic and where s* is the ith character of a string of length n. The hash value of an empty string is defined as zero. http://linuxgazette.net/issue57/tindale.html