Bitcoin Forum
May 02, 2024, 10:30:49 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Verify Dice Rolls on Windows Offline PC?  (Read 91 times)
zappylappy (OP)
Newbie
*
Offline Offline

Activity: 16
Merit: 4


View Profile
March 09, 2021, 04:10:52 PM
 #1

I roll the dice and generate a Private key with the bitaddress.org script on an airgapped Windows PC.

To be sure that the bitaddress.org works as expected I want to double check the conversion of the dice rolls to the Private Key.

However I found no script that runs in the browser (like bitaddress does) and takes the base6 dice rolls as input.

Any hints or ideas?
1714645849
Hero Member
*
Offline Offline

Posts: 1714645849

View Profile Personal Message (Offline)

Ignore
1714645849
Reply with quote  #2

1714645849
Report to moderator
"Governments are good at cutting off the heads of a centrally controlled networks like Napster, but pure P2P networks like Gnutella and Tor seem to be holding their own." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714645849
Hero Member
*
Offline Offline

Posts: 1714645849

View Profile Personal Message (Offline)

Ignore
1714645849
Reply with quote  #2

1714645849
Report to moderator
1714645849
Hero Member
*
Offline Offline

Posts: 1714645849

View Profile Personal Message (Offline)

Ignore
1714645849
Reply with quote  #2

1714645849
Report to moderator
1714645849
Hero Member
*
Offline Offline

Posts: 1714645849

View Profile Personal Message (Offline)

Ignore
1714645849
Reply with quote  #2

1714645849
Report to moderator
NotATether
Legendary
*
Online Online

Activity: 1596
Merit: 6720


bitcoincleanup.com / bitmixlist.org


View Profile WWW
March 09, 2021, 04:23:03 PM
 #2

If you install Python 3, will this script suffice if you run it from Command Prompt?

I don't have an HTML version of this, sorry.

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.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
March 09, 2021, 10:04:47 PM
 #3

Did you not try the suggestions from your previous thread? https://bitcointalk.org/index.php?topic=5320649.0 Huh

You should be able to install Cygwin on the offline machine which will give you the ability to use "bash" scripts... instructions for an offline install are here: https://wincrunch.com/cygwin-offline-installer-download-windows-7-8-10-xp-vista/

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
zappylappy (OP)
Newbie
*
Offline Offline

Activity: 16
Merit: 4


View Profile
March 13, 2021, 12:28:04 PM
Merited by NotATether (1)
 #4

Did you not try the suggestions from your previous thread? https://bitcointalk.org/index.php?topic=5320649.0 Huh

You should be able to install Cygwin on the offline machine which will give you the ability to use "bash" scripts... instructions for an offline install are here: https://wincrunch.com/cygwin-offline-installer-download-windows-7-8-10-xp-vista/

I read the suggestions, but - as I was asking - I am looking for a script that runs in a browser: I want to keep the codebase as small as possible. Bigger codebase means more complexity and means less security.

I solved the problem and wrote a JavaScript:


<script>
function parser(str) {
    let num = 0n;
    base = BigInt(6);
    for (const digit of str) {
        num *= base;
        num += BigInt(parseInt(digit, 6));
    }
    return num;
}

const big = "012345... <put your 99 dice rolls here>";
const num = parser(big);
const base16 = num.toString(16);
document.write (base16);
</script>
bob123
Legendary
*
Offline Offline

Activity: 1624
Merit: 2481



View Profile WWW
March 14, 2021, 11:58:43 AM
 #5

I read the suggestions, but - as I was asking - I am looking for a script that runs in a browser: I want to keep the codebase as small as possible. Bigger codebase means more complexity and means less security.

I solved the problem and wrote a JavaScript:

More complexity does not automatically mean less security.
But i tell you what.. using javascript instead of a proper coding language actually means less security.

You should never do crypto in your browser. This includes using javascript for that.

A 20-30 line python code does not add too much complexity that it would decrease the security. Especially not compared to anything which is related to javascript.

NotATether
Legendary
*
Online Online

Activity: 1596
Merit: 6720


bitcoincleanup.com / bitmixlist.org


View Profile WWW
March 14, 2021, 03:52:59 PM
 #6

~

That's great if it solves your problem, but I noticed that yours just makes a huge integer private key out of the dice rolls and not a base58 WIF Huh

You should never do crypto in your browser. This includes using javascript for that.

It just hit me that there is a way to extract private keys from the browser even if you are offline.

Scripts have a local storage in the browser that stores keys and values, and if some site is foolhardy enough to save private keys or other secrets there, all someone has to do is exploit a browser CVE that let's you see any site's local storage and then steal the private key at a later date.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
March 18, 2021, 10:04:07 PM
 #7

I read the suggestions, but - as I was asking - I am looking for a script that runs in a browser: I want to keep the codebase as small as possible. Bigger codebase means more complexity and means less security.
And how big do you think the codebase for a browser is? Huh

By using a browser you are exposing yourself to a huge attack surface that you have even less chance of being able to personally validate... unless you're going to audit the codebase for the browser and ensure that it isn't doing anything stupid (like NotATether mentioned above)...

A simple bash script or 20-30 line Python script will be objectively a lot more secure than trusting browser code and javascript.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!