import math
import hashlib
import codecs
import sys
def main():
s = input("Enter the dice numbers: ")
group = input("Enter the number of digits moved in one group: ")
group = int(group)
fil = input("path to output file: ")
# Ensure that we have a 256-bit number
digit2 = math.floor(math.log(6*len(s))/math.log(2) + 1)
if digit2 > 256:
raise ValueError("Number greater than 256 bits")
f = open(fil, "w")
# Try all combinations
print("generating all combinations")
transpose_s(sixtozero(s), group, f)
def transpose_s(s, n, f):
combs = []
i = 0
l = len(s)
j = min(n, l)
if j - i < n:
raise ValueError("dice number length is smaller than number of digits to transpose")
while j < len(s):
slice = s[i:j]
ss = s[:i] + s[j:]
# l-n is length of ss
ll = l-n
for k in range(0,ll):
t = ss[:k] + slice + ss[k:]
combs.append(t)
i+=1
j+=1
cc = len(combs)
print("{} possible transposes found".format(cc))
print("converting to int")
for ii in range(0,cc):
combs[ii] = to_int(combs[ii])
print("converting to hex")
for ii in range(0,cc):
combs[ii] = hex_no0x(combs[ii])
print("converting to privkey WIF")
privkeys = []
for ii in range(0,cc):
privkeys.append(construct_privkey(combs[ii]))
for ii in range(0,cc):
privkeys[ii] = base58(privkeys[ii])
lines = "\r\n".join(privkeys)
f.write(lines)
f.close()
print("Finished")
sys.exit()
def hex_no0x(i):
return hex(i)[2:]
# https://gist.github.com/Jun-Wang-2018/3105e29e0d61ecf88530c092199371a7
def construct_privkey(PK0):
PK0 = '{:0>64}'.format(PK0)
PK1 = '80'+ PK0
PK2 = hashlib.sha256(codecs.decode(PK1, 'hex'))
PK3 = hashlib.sha256(PK2.digest())
checksum = codecs.encode(PK3.digest(), 'hex')[0:8]
PK4 = PK1 + str(checksum)[2:10]
return PK4
# Define base58
def base58(address_hex):
alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
b58_string = ''
# Get the number of leading zeros
leading_zeros = len(address_hex) - len(address_hex.lstrip('0'))
# Convert hex to decimal
address_int = int(address_hex, 16)
# Append digits to the start of string
while address_int > 0:
digit = address_int % 58
digit_char = alphabet[digit]
b58_string = digit_char + b58_string
address_int //= 58
# Add ‘1’ for each 2 leading zeros
ones = leading_zeros // 2
for one in range(ones):
b58_string = '1' + b58_string
return b58_string
def sixtozero(s):
l = list(s)
for i in range(0,len(s)):
if s[i] == "6":
l[i] = "0"
return "".join(l)
def to_int(s):
si = int(s, 6)
return si
if __name__ == "__main__":
main()
This will make a file with all possible private keys, one on each line. For example, the dice sequence "123" and one character transposed, makes the private keys:
5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreGRmRFDZ
5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreKnSXYds
5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreKnSXYds
5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreGRmRFDZ
There are some duplicates, probably because some transposes are equivalent like swapping positions 1-2 and 2-1.
The next step after retrieving all these private keys is to use LoyceV's list of addresses with a balance to see which ones are inside both lists.
edit: fixed error in sixtozero()