Example #1
0
        public static bool CheckHash(byte[] data, int hardness, uint nonce)
        {
            Pack p    = new Pack(data, nonce);
            uint hash = FNVHash.Hash_1a_32(Util.ObjectToByteArray(p));

            return(hash < 1 << (32 - hardness));
        }
Example #2
0
        public static uint CrunchHash(byte[] data, int hardness, Action <uint, uint> cb = null)
        {
            if (hardness < 0 || hardness > 31)
            {
                throw new Exception("Hardness must be between 0 and 31");
            }

            //give cb a dummy value, so we're not calling an if-statement every loop
            if (cb == null)
            {
                cb = (uint h, uint n) => {};
            }

            Pack p = new Pack(data);

            uint hash;

            do
            {
                hash = FNVHash.Hash_1a_32(Util.ObjectToByteArray(p));
                cb(hash, p.nonce);
            } while((hash >= 1 << (32 - hardness)) && ++p.nonce != 0);

            return(p.nonce);
        }