Esempio n. 1
0
        public void GlobalSetup()
        {
            var path = Path.GetDirectoryName(typeof(StringHash).GetTypeInfo().Assembly.Location);

            path = Path.Combine(path, "Files", "JEOPARDY_CSV.csv");

            List <byte[]> list = new();

            using var reader = new StreamReader(path);
            using var csv    = new CsvReader(reader, CultureInfo.InvariantCulture);
            csv.Read();
            csv.ReadHeader();
            StringBuilder stringBuilder = new StringBuilder();

            while (csv.Read())
            {
                var str = csv.GetField <string>(6);
                stringBuilder.Append(" " + str);
                list.Add(Encoding.UTF8.GetBytes(str));
            }
            _sentences = list.ToArray();
            _longText  = Encoding.UTF8.GetBytes(stringBuilder.ToString());

            list.Clear();
            path = Path.GetDirectoryName(typeof(StringHash).GetTypeInfo().Assembly.Location);
            using var streamReader = new StreamReader(new FileStream(Path.Combine(path, "Files", "words.txt"), FileMode.Open));
            while (!streamReader.EndOfStream)
            {
                list.Add(Encoding.UTF8.GetBytes(streamReader.ReadLine() ?? ""));
            }

            _words = list.ToArray();

            _sha1 = System.Data.HashFunction.HashAlgorithm.HashAlgorithmWrapperFactory.Instance.Create(
                new HashAlgorithmWrapperConfig()
            {
                InstanceFactory = SHA1.Create
            });
            _md5 = System.Data.HashFunction.HashAlgorithm.HashAlgorithmWrapperFactory.Instance.Create(
                new HashAlgorithmWrapperConfig()
            {
                InstanceFactory = MD5.Create
            });
            _sha512 = System.Data.HashFunction.HashAlgorithm.HashAlgorithmWrapperFactory.Instance.Create(
                new HashAlgorithmWrapperConfig()
            {
                InstanceFactory = SHA512.Create
            });

            _blake2   = System.Data.HashFunction.Blake2.Blake2BFactory.Instance.Create();
            _city     = System.Data.HashFunction.CityHash.CityHashFactory.Instance.Create();
            _fnv1     = System.Data.HashFunction.FNV.FNV1Factory.Instance.Create();
            _fnv1A    = System.Data.HashFunction.FNV.FNV1aFactory.Instance.Create();
            _jenkins3 = System.Data.HashFunction.Jenkins.JenkinsLookup3Factory.Instance.Create();
            _murmur3  = System.Data.HashFunction.MurmurHash.MurmurHash3Factory.Instance.Create();
            _pearson  = System.Data.HashFunction.Pearson.PearsonFactory.Instance.Create();
            _xxHash   = System.Data.HashFunction.xxHash.xxHashFactory.Instance.Create();
        }
Esempio n. 2
0
        /// <summary>
        /// return hash
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] CalculateHash(byte[] data)
        {
            Blake2BConfig config = new Blake2BConfig();

            config.HashSizeInBits = 256;
            IBlake2B blake2B = Blake2BFactory.Instance.Create(config);

            return(blake2B.ComputeHash(data).Hash);
        }
Esempio n. 3
0
        /// <summary>
        /// use UTF8 encode data and calculate hash
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] CalculateHash(string data)
        {
            Blake2BConfig config = new Blake2BConfig();

            config.HashSizeInBits = 256;
            IBlake2B blake2B = Blake2BFactory.Instance.Create(config);

            byte[] bytes = Encoding.UTF8.GetBytes(data);
            return(blake2B.ComputeHash(bytes).Hash);
        }
Esempio n. 4
0
        /**************************************************************************/

        static Macroscope()
        {
            SuppressStaticDebugMsg = true;
            BlakeHasher            = Blake2BFactory.Instance.Create();
            ShaHasher = HashAlgorithm.Create("SHA256");
        }