Пример #1
0
        internal float CalculateRoll(ServerSeed serverSeed)
        {
            var key = serverSeed.HexString;
            var text = ClientSeed + "-" + Nonce;

            // Generate HMAC-SHA256 hash using server seed as key and text as message
            var algorithm = WinRTCrypto.MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha512);
            var hasher = algorithm.CreateHash(Encoding.UTF8.GetBytes(key));
            hasher.Append(Encoding.UTF8.GetBytes(text));
            var bytes = hasher.GetValueAndReset();

            // Keep grabbing hash bytes while the lucky number is greater than 10^6
            for (var i = 0; i + 2 < bytes.Length; i += 2) {
                // Start calculating the lucky number using the next 3 bytes
                var lucky = (bytes[i] << 16) + (bytes[i + 1] << 8) + bytes[i + 2];

                // Determine whether the iteration count is odd or even
                if (i % 4 == 0) {
                    // Even: Use the first 5 digits of the hex string from the 3 bytes
                    lucky = (lucky - lucky % 16) >> 4;

                } else {
                    // Odd: Use the last 5 digits of the hex string from the 3 bytes
                    lucky %= 2 << 24;
                }

                // Return a lucky number if possible
                if (lucky < 1000000) {
                    return (float)(lucky % 10000) / 100;
                }
            }

            // If the end of the hash is reached, just default to the highest number
            return 99.99F;
        }
Пример #2
0
        internal float CalculateRoll(ServerSeed serverSeed)
        {
            var key  = serverSeed.HexString;
            var text = ClientSeed + "-" + Nonce;

            // Generate HMAC-SHA256 hash using server seed as key and text as message
            var algorithm = WinRTCrypto.MacAlgorithmProvider.OpenAlgorithm(MacAlgorithm.HmacSha512);
            var hasher    = algorithm.CreateHash(Encoding.UTF8.GetBytes(key));

            hasher.Append(Encoding.UTF8.GetBytes(text));
            var bytes = hasher.GetValueAndReset();

            // Keep grabbing hash bytes while the lucky number is greater than 10^6
            for (var i = 0; i + 2 < bytes.Length; i += 2)
            {
                // Start calculating the lucky number using the next 3 bytes
                var lucky = (bytes[i] << 16) + (bytes[i + 1] << 8) + bytes[i + 2];

                // Determine whether the iteration count is odd or even
                if (i % 4 == 0)
                {
                    // Even: Use the first 5 digits of the hex string from the 3 bytes
                    lucky = (lucky - lucky % 16) >> 4;
                }
                else
                {
                    // Odd: Use the last 5 digits of the hex string from the 3 bytes
                    lucky %= 2 << 24;
                }

                // Return a lucky number if possible
                if (lucky < 1000000)
                {
                    return((float)(lucky % 10000) / 100);
                }
            }

            // If the end of the hash is reached, just default to the highest number
            return(99.99F);
        }
Пример #3
0
 /// <summary>Verifies the validity of the bet's outcome.</summary>
 /// <param name="serverSeed">The server seed which was used for rolling.</param>
 /// <returns>True whether the outcome of the bet was calculated fairly.</returns>
 public bool Verify(ServerSeed serverSeed)
 {
     return(CalculateRoll(serverSeed).Equals(Roll));
 }
Пример #4
0
 /// <summary>Verifies the validity of the bet's outcome.</summary>
 /// <param name="serverSeed">The server seed which was used for rolling.</param>
 /// <returns>True whether the outcome of the bet was calculated fairly.</returns>
 public bool Verify(ServerSeed serverSeed)
 {
     return CalculateRoll(serverSeed).Equals(Roll);
 }