コード例 #1
0
        public Tuple <byte[], Guid> PoW(int difficulty, BlockchainEntry bce)
        {
            bool finish = false;


            while (!finish)
            {
                Guid   nonce           = Guid.NewGuid();
                byte[] bytesToBeHashed = bce.HashPowEntry(nonce);
                byte[] hash            = null;

                using (SHA512 shaM = new SHA512Managed())
                {
                    hash = shaM.ComputeHash(bytesToBeHashed);
                }

                int clz = CountLeadingZeros(hash);

                if (clz == difficulty)
                {
                    return(Tuple.Create(hash, nonce));
                }
            }

            return(null);
        }
コード例 #2
0
        public Tuple <byte[], Guid> PoW(ulong difficulty, BlockchainEntry bce)
        {
            bool finish = false;


            while (!finish)
            {
                Guid   nonce           = Guid.NewGuid();
                byte[] bytesToBeHashed = bce.HashPowEntry(nonce);
                byte[] hash            = null;

                using (SHA512 shaM = new SHA512Managed())
                {
                    hash = shaM.ComputeHash(bytesToBeHashed);
                }

                ulong dif = BitConverter.ToUInt64(hash, 0);

                if (dif < difficulty)
                {
                    return(Tuple.Create(hash, nonce));
                }
            }

            return(null);
        }