Author

Topic: Software to convert 256 1 & 0's to WIF private key? (Read 3436 times)

sr. member
Activity: 751
Merit: 253
Thank You!
staff
Activity: 3458
Merit: 6793
Just writing some code
Thanks Knight,

I got it, I had do a little trial and error to figure out what else I needed to change.  Thank You!
No problem!

Why can't we just have a script to do this so we don't have to compile each change?
Because c isn't a scripting language. If you want a script, find a program in a scripting language that does this.
sr. member
Activity: 751
Merit: 253
Thanks Knight,

I got it, I had do a little trial and error to figure out what else I needed to change.  Thank You!


Why can't we just have a script to do this so we don't have to compile each change?
staff
Activity: 3458
Merit: 6793
Just writing some code
Thanks, I am still missing something:

Here is the result:
WIF      : KxaZ3DctC1ximsBBcQ37TcaqcRvqxyo9AkvcEpRCtc4zfnD9YXcQ
should be: 5J89cr5WGdvQWeeekN5ZGzuXVsWREbAYku6MDeUgrJTjX1ZHhCX
Your expected result is uncompressed. Uncompressed keys begin with a 5. Compressed begin with a K or L. Follow my instructions in the above post to get uncompressed keys.

Also, note that most clients now use compressed keys as the public keys are smaller and thus save space.
sr. member
Activity: 751
Merit: 253
Thanks, I am still missing something:

Here is the result:
WIF      : KxaZ3DctC1ximsBBcQ37TcaqcRvqxyo9AkvcEpRCtc4zfnD9YXcQ
should be: 5J89cr5WGdvQWeeekN5ZGzuXVsWREbAYku6MDeUgrJTjX1ZHhCX

Here is my ex-wif.c :
include "common.h"
#include "base58.h"
#include "hash.h"

int main() {
    uint8_t priv_bytes[32] = {
        0x28,0x8f,0x39,0xbb,0xfd,0x36,0xda,0x5a,
        0x12,0xd1,0x62,0xcb,0x18,0x97,0xc9,0x02,
        0x28,0x8b,0x39,0xbb,0x36,0xda,0x5a,0x12,
        0xd1,0x62,0xcb,0x18,0x97,0xc9,0x02,0x3d
    };
    uint8_t wif_bytes[33];
    char *wif;

    const char wif_exp[] = "cNKkmrwHuShs2mvkVEKfXULxXhxRo3yy1cK6sq62uBp2Pc8Lsa76";

    /* */

    bbp_print_hex("priv", priv_bytes, sizeof(priv_bytes));

    wif_bytes[0] = 0x80;
    memcpy(wif_bytes + 1, priv_bytes, 32);

    wif = bbp_base58check(wif_bytes, 34);
    printf("WIF      : %s\n", wif);
    printf("WIF (exp): %s\n", wif_exp);
    free(wif);

    return 0;
}

staff
Activity: 3458
Merit: 6793
Just writing some code
Yes, that was easy, Thank You!!

Anyone know why I do not get the correct WIF with the ./wif

using this hex input?:
0x28, 0x8f, 0x39, 0xbb, 0xfd, 0x36, 0xda, 0x5a,
0x12, 0xd1, 0x62, 0xcb, 0x18, 0x97, 0xc9, 0x02,
0x28, 0x8b, 0x39, 0xbb, 0x36, 0xda, 0x5a, 0x12,
0xd1, 0x62, 0xcb, 0x18, 0x97, 0xc9, 0x02, 0x3d

I get:
cNwYW8cjd5eywJeSzorEpw5uEfEFdRtqEo55MEsiPiizv4Dk4mNr

the coin flip post calculated:
5J89cr5WGdvQWeeekN5ZGzuXVsWREbAYku6MDeUgrJTjX1ZHhCX
That is because it is doing it for testnet. You need to change the line
Code:
wif_bytes[0] = 0xef;
to
Code:
wif_bytes[0] = 0x80;

Also, if you want the uncompressed key, you need to comment out
Code:
wif_bytes[33] = 0x01;
and change
Code:
uint8_t wif_bytes[34];
to
Code:
uint8_t wif_bytes[33];
sr. member
Activity: 751
Merit: 253
Yes, that was easy, Thank You!!

Anyone know why I do not get the correct WIF with the ./wif

using this hex input?:
0x28, 0x8f, 0x39, 0xbb, 0xfd, 0x36, 0xda, 0x5a,
0x12, 0xd1, 0x62, 0xcb, 0x18, 0x97, 0xc9, 0x02,
0x28, 0x8b, 0x39, 0xbb, 0x36, 0xda, 0x5a, 0x12,
0xd1, 0x62, 0xcb, 0x18, 0x97, 0xc9, 0x02, 0x3d

I get:
cNwYW8cjd5eywJeSzorEpw5uEfEFdRtqEo55MEsiPiizv4Dk4mNr

the coin flip post calculated:
5J89cr5WGdvQWeeekN5ZGzuXVsWREbAYku6MDeUgrJTjX1ZHhCX
legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
Or is there an easy way to convert this:
288f39bbfd36da5a12d162cb1897c902288b39bb36da5a12d162cb1897c9023d

to
0x28, 0x8f, 0x39, 0xbb, 0xfd, 0x36, 0xda, 0x5a,
0x12, 0xd1, 0x62, 0xcb, 0x18, 0x97, 0xc9, 0x02,
0x28, 0x8b, 0x39, 0xbb, 0x36, 0xda, 0x5a, 0x12,
0xd1, 0x62, 0xcb, 0x18, 0x97, 0xc9, 0x02, 0x3d

Thanks!

Code:
$ echo "288f39bbfd36da5a12d162cb1897c902288b39bb36da5a12d162cb1897c9023d" | sed -e 's/\(.\{2\}\)/0x\1,/g' | sed -e 's/.$//'
0x28,0x8f,0x39,0xbb,0xfd,0x36,0xda,0x5a,0x12,0xd1,0x62,0xcb,0x18,0x97,0xc9,0x02,0x28,0x8b,0x39,0xbb,0x36,0xda,0x5a,0x12,0xd1,0x62,0xcb,0x18,0x97,0xc9,0x02,0x3d

^^Pretty easy Wink  Hope it helps.
sr. member
Activity: 751
Merit: 253
Great, thanks!

I am working thru the numbers to make sure I have it correct, I am comparing to the numbers calculated in this thread
https://bitcointalksearch.org/topic/m.10342157

to get the hex, (I know this is probably the hard way), In python I am converting binary to decimal, then to get hex I just use hex(decimal), and I get:

288f39bbfd36da5a12d162cb1897c902288b39bb36da5a12d162cb1897c9023d  (same as coin flip thread)

So when I edit my ex-wif.c file, I need to replace all the:
        0x16, 0x26, 0x07, 0x83, 0xe4, 0x0b, 0x16, 0x73,
        0x16, 0x73, 0x62, 0x2a, 0xc8, 0xa5, 0xb0, 0x45,
        0xfc, 0x3e, 0xa4, 0xaf, 0x70, 0xf7, 0x27, 0xf3,
        0xf9, 0xe9, 0x2b, 0xdd, 0x3a, 0x1d, 0xdc, 0x42

with
288f39bbfd36da5a12d162cb1897c902288b39bb36da5a12d162cb1897c9023d

But that will create a problem, not the right format.

So I enter this:
0x28, 0x8f, 0x39, 0xbb, 0xfd, 0x36, 0xda, 0x5a,
0x12, 0xd1, 0x62, 0xcb, 0x18, 0x97, 0xc9, 0x02,
0x28, 0x8b, 0x39, 0xbb, 0x36, 0xda, 0x5a, 0x12,
0xd1, 0x62, 0xcb, 0x18, 0x97, 0xc9, 0x02, 0x3d

Compile and execute ./wif
But I get this:
cNwYW8cjd5eywJeSzorEpw5uEfEFdRtqEo55MEsiPiizv4Dk4mNr
Instead of the answer in the coin flip thread  (and when I tried to import private key, core said invalid private key encoding)
I guess I converted long string wrong?.


Also,
Is there an easy way to change this line (unit8_t) so I can just add in the HEX long string??
uint8_t priv_bytes[32] = {

Or is there an easy way to convert this:
288f39bbfd36da5a12d162cb1897c902288b39bb36da5a12d162cb1897c9023d

to
0x28, 0x8f, 0x39, 0xbb, 0xfd, 0x36, 0xda, 0x5a,
0x12, 0xd1, 0x62, 0xcb, 0x18, 0x97, 0xc9, 0x02,
0x28, 0x8b, 0x39, 0xbb, 0x36, 0xda, 0x5a, 0x12,
0xd1, 0x62, 0xcb, 0x18, 0x97, 0xc9, 0x02, 0x3d

Thanks!
sr. member
Activity: 689
Merit: 269
root@ubuntu-server:/home/user/bitcointools/pybitcointools-master/bitcoin#[/i] pybtctool XXXXXXXX 101010101010....1010101010101010

Output WIF private key

Thanks!!


see the program

https://github.com/keeshux/basic-blockchain-programming/blob/master/ex-wif.c

just compile it and put your private key in hexadecimal to the priv_bytes variable

no need to pay me

EDIT: compile it like this

gcc  ex-wif.c  -lcrypto -lssl -ldl -o wif

then run the wif program:

./wif

and u get your wif key
sr. member
Activity: 751
Merit: 253
OK,  0.2000  BTC for first person to help me with simple answer. 

Reply here that you sent me PM so everyone can see who was first in line, then when you confirm you are first to respond, PM me the solution.  If you are 2nd in line, do not send me the solution until I PM you that #1 solution did not work.  (I dont want to pay 0.2 * 100 people for an easy answer).   If it does not wot work, I will communicate with #1 to troubleshoot my typing errors before asking #2 reply to send the solution.

I am at work and I will try to check this frequently throughout the day, but at certain times it may be an hour or so between me checking for responses.

I have bitcointools installed on an ubuntu server and running the examples in the README.txt work with no problems.

I need some help with the exact syntax of the commands:

I need to know EXACTLY what to replace the XXXXX with and any formatting to input 256 1&0's to get output WIF private keys.

root@ubuntu-server:/home/user/bitcointools/pybitcointools-master/bitcoin#
pybtctool XXXXXXXX 101010101010....1010101010101010

Output WIF private key

Thanks!!
sr. member
Activity: 689
Merit: 269

Thank You

Check basic-blockchain-programming

https://github.com/keeshux/basic-blockchain-programming/blob/master/ex-ec-keypair.c

Code:
    uint8_t priv_bytes[32] = {
        0x16, 0x26, 0x07, 0x83, 0xe4, 0x0b, 0x16, 0x73,
        0x16, 0x73, 0x62, 0x2a, 0xc8, 0xa5, 0xb0, 0x45,
        0xfc, 0x3e, 0xa4, 0xaf, 0x70, 0xf7, 0x27, 0xf3,
        0xf9, 0xe9, 0x2b, 0xdd, 0x3a, 0x1d, 0xdc, 0x42
    };

priv_bytes is exactly what you wanted, your variable of 256 bits
sr. member
Activity: 751
Merit: 253
It does, the commands are encode_privkey and decode_privkey. Look at https://github.com/vbuterin/pybitcointools/blob/master/bitcoin/main.py#L222 for some reference.

Thank You
staff
Activity: 3458
Merit: 6793
Just writing some code
I think pybitcointools: https://github.com/vbuterin/pybitcointools has what you want. I

Thanks, I want something that I can run totally offline, readme says:
* Relies on centralized service (blockchain.info) for blockchain operations, although operations do have backups (eligius, blockr.io)
It can be run offline. Just that if you want to do anything involving the network (e.g. send transactions), then you need to be connected to the internet (duh).

Also, not sure if I see the command to take one or both binary or decimal to WIF, I do see these instructions:

### Listing of main commands:

* privkey_to_pubkey    : (privkey) -> pubkey
* privtopub            : (privkey) -> pubkey
* pubkey_to_address    : (pubkey) -> address
* pubtoaddr            : (pubkey) -> address
* privkey_to_address   : (privkey) -> address
* privtoaddr           : (privkey) -> address


but nothing for private key in binary or decimal to WIF.

There has to be a simple code to do this somewhere.  (yeah, I know its not that simple)
It does, the commands are encode_privkey and decode_privkey. Look at https://github.com/vbuterin/pybitcointools/blob/master/bitcoin/main.py#L222 for some reference.
sr. member
Activity: 751
Merit: 253
I think pybitcointools: https://github.com/vbuterin/pybitcointools has what you want. I

Thanks, I want something that I can run totally offline, readme says:
* Relies on centralized service (blockchain.info) for blockchain operations, although operations do have backups (eligius, blockr.io)

Also, not sure if I see the command to take one or both binary or decimal to WIF, I do see these instructions:

### Listing of main commands:

* privkey_to_pubkey    : (privkey) -> pubkey
* privtopub            : (privkey) -> pubkey
* pubkey_to_address    : (pubkey) -> address
* pubtoaddr            : (pubkey) -> address
* privkey_to_address   : (privkey) -> address
* privtoaddr           : (privkey) -> address


but nothing for private key in binary or decimal to WIF.

There has to be a simple code to do this somewhere.  (yeah, I know its not that simple)
staff
Activity: 3458
Merit: 6793
Just writing some code
I think pybitcointools: https://github.com/vbuterin/pybitcointools has what you want. I
sr. member
Activity: 751
Merit: 253
Does anyone know of a python/C program to input binary or decimal (or both) and output WIF private key?
Jump to: