import hashlib
import codecs
import sys
def main():
s = input("Enter the dice numbers: ")
# 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")
s0 = sixtozero(s)
i = to_int(s0)
h1 = hex(i)
h2 = hex_no0x(i)
p = construct_privkey(h2)
b = base58(p)
print("Private key hex: {}".format(h1))
print("Private key WIF: {}".format(b))
def hex_no0x(a):
b = hex(a)[2:]
return b
# 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()
Private key hex: 0x2bb6
Private key WIF: 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEss1w8VWDR3
Note that this code assumes that 6 represents 0 in base6, which can only represent the numbers 0,1,2,3,4,5.
Unless you are looking for stuff written in JavaScript Node.js, or you also want some HTML file to open a browser to it, "webbased script" and "can be used on an offline PC" sounds conflicting to me.