Author

Topic: base6 to base16 script beside bitaddress.org ? (Read 91 times)

legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
I guess you can reuse my other script that converts base6 to base58 if I modify it to return hex output instead?

Code:
import math
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()

Code:
Enter the dice numbers: 123456
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.



I am looking for a webbased script that converts base 6 (Dice) into base 16 (Private Key), that can be used on a offline PC.

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.
HCP
legendary
Activity: 2086
Merit: 4361
There is a simple bash script available here: https://github.com/swansontec/dice2key

It's not web-based, but it is very simple! Wink


They have a full writeup on creating keys from dice here: https://www.swansontec.com/bitcoin-dice.html
newbie
Activity: 16
Merit: 4
I am looking for a webbased script that converts base 6 (Dice) into base 16 (Private Key), that can be used on a offline PC.

I tried to code it, but parseInt (JavaScript Function) has a problem with big numbers:

var i = 32341234253543242345555;
out1 = parseInt (i, 6);
out2 = out1.toString(16);
document.write (out2);

I am also aware of bitaddress.org, but would like to have a second script that confirms the correct output of the later.

Has anyone a hint for a simple script?
Jump to: