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
.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];
return result % 1000000 == betResult;
}
hash = sha512.ComputeHash(hash);
}
}
}