-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameHash-N1000.py
64 lines (55 loc) · 2.63 KB
/
GameHash-N1000.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
## ---------------------------------------------------------------------------------
## GameHash-N1000.py
## Introducing the N1000 series GameHash generator!
## "Don't call it gambling, it's calculated risk taking."
## ~jacksonova
##
## The input file should have each line in the format of "serverSeed,clientSeed\n"
##
## As of February 2023, the resulting hash matches with single implementation games
## on Stake.com and Stake.US - i.e. Dice, Limbo, Baccarat, Wheel, Roulette, & Diamonds
##
## Visit the wiki for more info: https://github.com/nucleare/GameResultsGenerator/wiki
## Copyright (c) 2023 Dafordo Co. (DBA) - Join Discord @ https://discord.gg/wqZfjPUv73
## Released under an MIT License
## ---------------------------------------------------------------------------------
import hmac
import hashlib
import binascii
import sys
## Using Stake's "RNG" known as the byte_generator function
def byte_generator(serverSeed, clientSeed, nonce, cursor):
current_round = cursor // 32
current_round_cursor = cursor
current_round_cursor -= current_round * 32
while True:
hmac_result = hmac.new(serverSeed.decode().encode(), digestmod=hashlib.sha256)
hmac_result.update(f"{clientSeed}:{nonce}:{current_round}".encode())
buffer = hmac_result.digest()
## The float caluclation below is not used for the single implementation hashes, but includes for consistency
while current_round_cursor < 32:
yield buffer[current_round_cursor]
current_round_cursor += 1
current_round_cursor = 0
current_round += 1
## Remind users that an input file and output file is needed as arguments
def main():
if len(sys.argv) < 3:
print("Please provide the input file name and output file name as command line arguments")
sys.exit(1)
input_file = sys.argv[1]
output_file = sys.argv[2]
with open(input_file) as f:
data = f.readlines()
with open(output_file, 'w') as f:
for line in data:
serverSeed, clientSeed = line.strip().split(',')
serverSeed = serverSeed.encode()
for nonce in range(1, 1001): ## Sets the total number of nonce outcomes to produce
cursor = 0
gen = byte_generator(serverSeed, clientSeed, nonce, cursor)
output = [next(gen) for i in range(32)]
result = binascii.hexlify(bytes(output))
f.write(f"{serverSeed.decode()},{clientSeed},{nonce},{result.decode()}\n")
if __name__ == "__main__":
main()