Advertisement
Guest User

Untitled

a guest
Jan 17th, 2015
379
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. # Python just-dice.com verifier, based on the JavaScript verifiers described on the "Fair?" pages at just-dice.com
  4. #
  5. # example usage:
  6. #   python just-dice.py ia_zEVRJ_VqfHPDbqGEYm39d6d2yg58_t1brUjO2LwiDBVydO7sKh6Sulw8123ec 7ab7df124145d0fcf931c142aabcca2022f60775d6afa692be114c09ff4408cf 515035004112265853362847 12
  7. #   prints the last 10 lucky numbers, starting with roll 12 since the last randomize, which is this bet: https://just-dice.com/roll/23616559
  8.  
  9. import hashlib
  10. import hmac
  11. import sys
  12.  
  13. # parse command line arguments
  14. if len(sys.argv) < 5:
  15.     print("usage: python just-dice.py server-seed server-seed-hash client-seed last-roll [roll-count]")
  16.     exit(-1)
  17. print(sys.argv[1])
  18. serverSeed = sys.argv[1]
  19. serverSeedHash = sys.argv[2]
  20. clientSeed = sys.argv[3]
  21. lastNonce = int(sys.argv[4])
  22. nonceCount = 10
  23. if len(sys.argv) == 6:
  24.     nonceCount = int(sys.argv[5])
  25.  
  26. # convert string to binary array
  27. def str2bin(string):
  28.     return bytes(string, 'latin-1')
  29.  
  30. # test server hash
  31. hash_object = hashlib.sha256(str2bin(serverSeed))
  32. hash = hash_object.hexdigest()
  33. if hash == serverSeedHash:
  34.     print('Server secret hash is correct.')
  35. else:
  36.     print('Server secret hash check failed!')
  37.  
  38. # calculate and show lucky numbers
  39. for nonce in range(lastNonce, lastNonce - nonceCount, -1):
  40.     hash_object = hmac.new(str2bin(serverSeed), str2bin(clientSeed + ":" + str(nonce)), hashlib.sha512)
  41.     hash = hash_object.hexdigest()
  42.     i = 0
  43.     while True:
  44.         if i == 25:
  45.             l3 = hash[-3:]
  46.             l3p = int(l3, 16)
  47.             #print('last 3: ' + l3 + ' as int: ' + l3p)
  48.             roll = l3p / 10000
  49.             break
  50.         else:
  51.             f5 = hash[5 * i : 5 + 5 * i]
  52.             f5p = int(f5, 16)
  53.             #print(f5 + ' as int: ' + f5p);
  54.             if f5p < 1000000:
  55.                 roll = f5p / 10000
  56.                 break
  57.             i = i + 1
  58.     lucky = ('0' + '{:.4f}'.format(roll))[-7:]
  59.     print(str(nonce) + ": " + lucky)
Advertisement
RAW Paste Data Copied
Advertisement