Beispiel #1
0
        public IBF(int size, ICollection<IHashFunc> hashFunctions)
        {
            _hashSum = new int[size];
            _idSum = new long[size];
            _count = new int[size];

            _hFuncs = hashFunctions;
            _hcFunc = new MurmurHash3_x86_32()
            {
                Seed = 123456789
            };
        }
Beispiel #2
0
        //static public void FindCollision(IHashFunc hashFunc, byte[] ex)
        //{
        //    byte[] inp = new byte[ex.Length];
        //    string hash = "";
        //    string exHash = Encoding.ASCII.GetString(hashFunc.CalcHash(ex));
        //    ulong iterationsCounter = 0;

        //    Stopwatch stopwatch = new Stopwatch();

        //    stopwatch.Start();

        //    while (!hash.Equals(exHash))
        //    {
        //        iterationsCounter++;
        //        RandomizeByteArr(inp);

        //        hash = Encoding.ASCII.GetString(hashFunc.CalcHash(inp));
        //    }

        //    stopwatch.Stop();

        //    Console.WriteLine($"Found in {iterationsCounter} iterations \n Time spent {stopwatch.ElapsedMilliseconds} ms");
        //}

        //static public void RandomizeByteArr(byte[] inp)
        //{
        //    for (int i = 0; i < inp.Length; ++i)
        //        inp[i] = (byte)(random.Next(254)+1);
        //}

        static void ProofOfWork(IHashFunc hashFunc, string initStr, string matched)
        {
            string hash = "";
            ulong  iterationsCounter = 0;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            while (!hash.StartsWith(matched))
            {
                iterationsCounter++;

                hash = Encoding.ASCII.GetString(hashFunc.CalcHash(Encoding.ASCII.GetBytes(initStr + iterationsCounter.ToString())));
            }

            stopwatch.Stop();

            Console.WriteLine($"Found in {iterationsCounter} iterations \n Time spent {stopwatch.ElapsedMilliseconds} ms");
        }
Beispiel #3
0
 int CalcIdx(long id, IHashFunc hFunc)
 {
     return (int)(BitConverter.ToUInt32(hFunc.ComputeHash(BitConverter.GetBytes(id)), 0) % Size);
 }
Beispiel #4
0
 public void SetHashFunctions(ICollection<IHashFunc> hashFunctions)
 {
     _hFuncs = hashFunctions;
     _hcFunc = new MurmurHash3_x86_32()
     {
         Seed = 123456789
     };
 }