Bitcoin Forum
May 27, 2024, 03:24:22 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Warning: One or more bitcointalk.org users have reported that they strongly believe that the creator of this topic is a scammer. (Login to see the detailed trust ratings.) While the bitcointalk.org administration does not verify such claims, you should proceed with extreme caution.
Pages: [1]
  Print  
Author Topic: Fair bets in dice sites !!!  (Read 1341 times)
ubitcoin (OP)
Hero Member
*****
Offline Offline

Activity: 686
Merit: 500


View Profile
February 26, 2015, 12:18:46 PM
 #1

I want to attract the programmers to check those programs are really fair ??

Here is the actual SQL function ...... site uses.

create function dbo.CalculateBetResult
(
   @serverSeed binary(32),
   @clientSeed binary( 8 )
)
returns bigint
as
begin
   declare @hash binary(64)
   declare @index int
   declare @r bigint
   
   set @hash = HASHBYTES('SHA2_512', @serverSeed+@clientSeed)
   set @hash = HASHBYTES('SHA2_512', @hash)
   while 1=1
   begin
      
      set @index = 1
      while @index <= 64 - 3
      begin
         set @r = cast(substring(@hash, @index, 3) as bigint)
         if @r < 16000000
            return @r % 1000000
         set @index += 3
      end

      set @hash = HASHBYTES('SHA2_512', @hash)

   end
   return -1
end

------------------------------------------------------------------------------------------------------------------------------------------------


And here is some C# code you could also use to verify results.


static bool VerifyBetResult(string serverSeed, int clientSeed, int betNumber,
                            long betResult, string serverSeedHash = null)
{
    Func<string, byte[]> strtobytes = s => Enumerable
        .Range(0, s.Length / 2)
        .Select(x => byte.Parse(s.Substring(x * 2, 2), NumberStyles.HexNumber))
        .ToArray();
    byte[] server = strtobytes(serverSeed);
    byte[] client = BitConverter.GetBytes(clientSeed).Reverse().ToArray();
    byte[] num = BitConverter.GetBytes(betNumber).Reverse().ToArray();
    byte[] serverhash = serverSeedHash == null ? null : strtobytes(serverSeedHash);
    byte[] data = server.Concat(client).Concat(num).ToArray();
    using (SHA512 sha512 = new SHA512Managed())
    {
        if (serverhash != null)
            using (SHA256 sha256 = new SHA256Managed())
                if (!sha256.ComputeHash(server).SequenceEqual(serverhash))
                    throw new Exception("Server seed hash does not match server seed");
        byte[] hash = sha512.ComputeHash(sha512.ComputeHash(data));
        while (true)
        {
            for (int x = 0; x <= 61; x += 3)
            {
                long result = (hash
  • << 16) | (hash[x + 1] << 8 ) | hash[x + 2];
               if (result < 16000000)
                    return result % 1000000 == betResult;
            }
            hash = sha512.ComputeHash(hash);
        }
    }
}
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!