1

I have the following code

import hashlib
import binascii

def word_to_private_key(word):
    sha256_hash = hashlib.sha256(word.encode()).digest()
    private_key = binascii.hexlify(sha256_hash).decode()
    return private_key

word = "hello"
private_key = word_to_private_key(word)
print("Bitcoin Private Key:", private_key)

Here hello is converted into bitcoin private key. Surprisingly I see some transactions with that private key.

For any string of the word variable there is one btc private key

My question is - what is the relation between string and bitcoin private key? Could you make me understand in simple way?

Also why people talk about 12 word seed? Here one word is converted into private key.

1 Answer 1

1

As you can see in the code, the word is hashed using SHA256 to get the private key. Because private keys in Bitcoin have 32 bytes, you can't just use any word directly as a private key, and one way of converting it into a private key is to run it through a hash function that outputs 32 bytes, such as SHA256. (It should be obvious that creating a private key from a single English word isn't secure.)

BIP39 is the most commonly used standard for 12-word mnemonics. It doesn't use SHA256 but HMAC-SHA512, and usually isn't used for creating just one private key but an entire chain of private keys using BIP32.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.