Example #1
0
        /// <summary>
        /// Computes the FNV-1a 1024-bit hash for the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>The FNV-1a 1024-bit hash of the specified data.</returns>
        // ReSharper disable once InconsistentNaming
        private static string Fnv1a1024s(this string data)
        {
            using (HashAlgorithm alg = new Fnv1a1024())
            {
                BigInteger hash   = new BigInteger(alg.ComputeHash(UTF8.GetBytes(data)));
                string     value1 = (hash >> 768).ToString("X64", InvariantCulture);
                string     value2 = ((hash & _Second64Bytes) >> 512).ToString("X64", InvariantCulture);
                string     value3 = ((hash & _Third64Bytes) >> 256).ToString("X64", InvariantCulture);
                string     value4 = (hash & _Bottom64Bytes).ToString("X64", InvariantCulture);

                return("0x"
                       + value1?.Substring(value1.Length - 64)
                       + value2?.Substring(value2.Length - 64)
                       + value3?.Substring(value3.Length - 64)
                       + value4?.Substring(value4.Length - 64));
            }
        }
Example #2
0
        /// <summary>
        /// Computes the FNV-1a 1024-bit hash for the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>The FNV-1a 1024-bit hash of the specified data.</returns>
        // ReSharper disable once InconsistentNaming
        private static string Fnv1a1024s(this string data)
        {
            using (HashAlgorithm alg = new Fnv1a1024())
            {
                BigInteger hash   = new BigInteger(alg.ComputeHash(UTF8.GetBytes(data)).AddZero());
                string     value1 = (hash >> 768).ToString("X64", InvariantCulture);
                //// ReSharper disable ComplexConditionExpression
                string value2 = ((hash & Bitmasks.Second64Bytes) >> 512).ToString("X64", InvariantCulture);
                string value3 = ((hash & Bitmasks.Third64Bytes) >> 256).ToString("X64", InvariantCulture);
                //// ReSharper enable ComplexConditionExpression
                string value4 = (hash & Bitmasks.Bottom64Bytes).ToString("X64", InvariantCulture);

                return("0x"
                       + value1.Substring(value1.Length - 64)
                       + value2.Substring(value2.Length - 64)
                       + value3.Substring(value3.Length - 64)
                       + value4.Substring(value4.Length - 64));
            }
        }