Skip to content

Instantly share code, notes, and snippets.

@Dice64
Created August 4, 2013 18:19
Show Gist options
  • Save Dice64/6151316 to your computer and use it in GitHub Desktop.
Save Dice64/6151316 to your computer and use it in GitHub Desktop.
Verifying results on Dice64.com
import hashlib
import requests
# Doesn't currently do signature checking, we'll implement that in soon.
URL = "https://dice64.com"
def dsha256(input):
return hashlib.sha256(hashlib.sha256(input.decode('hex')).digest()).hexdigest()
def verify_bet(id):
r = requests.get(URL + '/api/bets/'+str(id))
if r.status_code != 200:
print "Couldn't find bet"
exit()
secret = r.json()['secret']
secret_hash = r.json()['secret_hash']
nonce = r.json()['nonce']
combined_hash = r.json()['combined_hash']
result = r.json()['result']
# Calculated results
combined = int(secret, base=16) + nonce
combined_hex = hex(combined)[2:].strip("L")
# Add preceeding zeros to make it 64 bytes in length
while len(combined_hex) < 64:
combined_hex = "0"+combined_hex
# Print output
print "\nSecret Hash - dsha256(secret)"
print "Calculated:", dsha256(secret)
print "Server val:", secret_hash
print "\nCombined Hash - dsha256(secret + nonce)"
print "Calculated:", dsha256(combined_hex)
print "Server val:", combined_hash
print "\nResult - dsha256(secret + nonce) mod 64"
print "Calculated:", long(combined_hash, base=16) % 64
print "Server val:", result
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('id', help='id of bet to check', type=int)
args = parser.parse_args()
verify_bet(args.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment