예제 #1
0
        public byte[] ComputeHash(Stream data, int hashLength = 32, int passes = 3)
        {
            if (data.Length < hashLength)
            {
                byte[] bytes = new byte[hashLength];
                data.Read(bytes, 0, hashLength);
                return(ComputeHash(bytes, hashLength, passes));
            }

            prng = new Prng((byte)data.Length);
            uint seed = 0;

            while (data.Position < data.Length)
            {
                byte b = (byte)data.ReadByte();
                seed ^= prng.NextByte((byte)(b * data.Position ^ seed));
            }
            prng = new Prng(seed);

            this.result = new byte[hashLength];

            for (int i = 0; i < passes * 2; i++)
            {
                data.Position = 0;
                while (data.Position < data.Length)
                {
                    byte b = (byte)data.ReadByte();
                    result[data.Position % hashLength] += (byte)(prng.NextByte(b) ^ (prng.NextByte((byte)data.Position) * b));
                }
            }

            return(result);
        }
예제 #2
0
        public new byte[] ComputeHash(byte[] data, int hashLength = 32, int passes = 3)
        {
            prng = new Prng((byte)data.Length);
            uint seed = 0;

            for (int i = 0; i < data.Length; i++)
            {
                seed += prng.NextByte((byte)(data[i] * i ^ seed));
            }
            prng = new Prng(seed);

            data = pad(data, hashLength);

            HashCore(data, hashLength, passes);
            return(result);
        }