BX is a program that is a command line tool that can generate a random seed, and then convert this into a private key. Next we can convert to a Wifi format and then a public key and a public address. You can download BX [here].
Generating Bitcoin keys |
Theory
With Bitcoin, we create a 256-bit random value for the private key and then convert it to Wallet Interchange Format key (WiF) format, which is a Base-58 form for the random key. This is the format that is stored in the Bitcoin Wallet. For example, a sample private key is:
Private key: 5c04990cf2fb95ca8749d4021100ee98b0744e81a5ec00a2177aeaf4b29c00d3
We then convert this into WiF format (Base-58) to give:
5JWp4FM7sfAAE88DW3yvGF5mQyrsEXeWzXZn79bg61Vg8YMfJjA
This can be stored in a Bitcoin wallet. Next, we can take the private key and a hash value and covert it into a useable Bitcoin address, such as:
1A3CohNBuB6kFAMtp3KFEYwv3Eu58F2HyN
≈The format of the keys is defined below, where we create a 256-bit private key and convert this to a WiF private key. Next, we generate a 512-bit public key and then take a 160-bit RIPEM-160 hash and convert it to a Bitcoin address:
The method is:
- 1. Generate seed value (s).
- 2. Take a copy of the seed value with a BIP39 format.
- 3. Generate secp256k1 private key (a) based on the seed.
- 4. Save the key in a Wifi format in a wallet.
- 5. Generate public key point pub=a.G.
- 6. p=RIPEMD(SHA256(pub))
- 7. Bitcoin ID = Base58(p)
Converting from seed to address
We can then easily write a PowerShell script to go through possible seed values and discover the associated private key, the public key, and the Bitcoin address:
$seed = bx seed "Seed: ",$seed $mn = bx mnemonic-new $seed "`nmnemonic: ",$mn $pri = bx ec-new $seed "`nEC private key: ",$pri $wif = bx ec-to-wif $pri "`nWif: ",$wif $pub = bx ec-to-public $pri "`nPublic key (compressed): ",$pub $pub = bx ec-to-public -u $pri "`nPublic key (uncompressed): ",$pub $sha256 = bx sha256 $pub "`nSHA256: ",$sha256 $rip160 = bx ripemd160 $sha256 "`nRIPEM160: ",$rip160 $add = bx address-encode $rip160 "`naAddress-encode: ",$add
A sample run gives:
Seed: e4e33f5137d45e1a7a38068336880a7c46aee2d050b1ba6f EC private key: 523d10d91fae53d1e19dd743c65d6320accfeea2f3d7c10e20f80f1fbb85da2f Wif: Kyya7y6xTVSAHGxCjMg98ysfsFbsuccRdxmWmubavTZ6rNxMGy97 Public key: 03db3880c618460d1657cf1740caf85fd8244377d07490213393bbeb861bbe49d3 SHA256: 847b7d776661f96adf090ec47119d8e5b27f53b889c7f981adb4668d50c3c512 RIPEMD160: 8b532e9e7c8ce82b4e7e0a218d5328e1a1513b98 address-encode: 1DhgaFzUHYXbuDYoV7oq6MGQM8J1tvxD4f
In this case, we start with a seed of “e4e33f5137d4 ... aee2d050b1ba6f”, and then can generate a new 256-bit private key of “523d10d91fae53d ... 10e20f80f1fbb85da2f”. It can then be converted into a Wif format of “Kyya7y6xTVSAHG ... WmubavTZ6rNxMGy97”. Next, we generate the public key of “03db3880c618460d165 ... 213393bbeb861bbe49d3”. In this case, we have a compressed public key point, and is the x-axis point, and a “02” if the y-point is even, or a “03” if the point is odd. If we try another key, we get an odd y-axis point. Next we create a SHA256 hash of the public key to produce, "847b7d776661f96a ... b889c7f981adb4668d50c3c512", and then a RIPEMD160 to "8b532e9e7 ... 8d5328e1a1513b98", and then to encode as a Bitcoin address of "1DhgaFzUH ... QM8J1tvxD4f".