-2

有很多散列方法,但我想用 8096 位长组成位散列。有可能实现这一目标吗?

例如,当我输入“House”时,我应该得到如下字符串:

"0101010001010101..." (8096 bits)

我怎样才能做到这一点(使用 C# 4.0 可以)?

如果你想知道我为什么需要这样的东西,我需要它来比较签名文件和向量空间模型。

4

1 回答 1

2

对于快速非加密哈希,您可以检查FNV 系列。通过仔细和适当的变化,您应该能够构建一个相当快的 8096 位散列。

如果速度不是主要考虑因素,而是简单性和质量,那么您可以简单地使用 MD5 的变体来制作非加密哈希。

哈希(x) = MD5(0 || x) || MD5(1 || x) ... MD5(62 || x) || MD5(63 || x)<32>,其中“||” 是连接操作,仅使用最终散列的低 32 位,将为您提供 8096 位散列。

编辑

这是显示 MD5 概念的小代码示例:

using System;
using System.Security.Cryptography;
using System.Text;

namespace Hash8096
{
    class MainClass
    {
        public static byte [] H8096(byte [] x) {
            byte [] Result = new byte[8096 / 8];
            byte [] Xplus1 = new byte[x.Length + 1];
            x.CopyTo(Xplus1, 1);
            int ResultOffset = 0;
            int AmountLeft = Result.Length;
            for (int i=0; i<64; i++) {
                // do MD5(i || x)
                var md5 = MD5.Create();
                Xplus1[0] = (byte) i;
                var hash = md5.ComputeHash(Xplus1);
                int NumToCopy = Math.Min(hash.Length, AmountLeft);
                Array.Copy(hash, 0, Result, ResultOffset,NumToCopy);
                ResultOffset += NumToCopy;
                AmountLeft -= NumToCopy;
            }
            return Result;
        }

        public static void Main (string[] args)
        {
            byte [] x = Encoding.UTF8.GetBytes("Hello World!");
            byte [] MonsterHash = H8096(x);
            Console.WriteLine ("Monster hash in hex follows:");
            Console.WriteLine(BitConverter.ToString(MonsterHash));
        }
    }
}
于 2012-12-31T00:04:04.007 回答