Bitcoin Forum
May 07, 2024, 12:14:14 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Software to convert 256 1 & 0's to WIF private key?  (Read 3415 times)
altcointalk14 (OP)
Sr. Member
****
Offline Offline

Activity: 751
Merit: 251


View Profile
February 12, 2016, 07:27:25 PM
 #1

Does anyone know of a python/C program to input binary or decimal (or both) and output WIF private key?
1715084054
Hero Member
*
Offline Offline

Posts: 1715084054

View Profile Personal Message (Offline)

Ignore
1715084054
Reply with quote  #2

1715084054
Report to moderator
1715084054
Hero Member
*
Offline Offline

Posts: 1715084054

View Profile Personal Message (Offline)

Ignore
1715084054
Reply with quote  #2

1715084054
Report to moderator
The Bitcoin network protocol was designed to be extremely flexible. It can be used to create timed transactions, escrow transactions, multi-signature transactions, etc. The current features of the client only hint at what will be possible in the future.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3388
Merit: 6631


Just writing some code


View Profile WWW
February 12, 2016, 08:00:08 PM
 #2

I think pybitcointools: https://github.com/vbuterin/pybitcointools has what you want. I

altcointalk14 (OP)
Sr. Member
****
Offline Offline

Activity: 751
Merit: 251


View Profile
February 12, 2016, 08:15:19 PM
 #3

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)
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3388
Merit: 6631


Just writing some code


View Profile WWW
February 12, 2016, 08:39:58 PM
 #4

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.

altcointalk14 (OP)
Sr. Member
****
Offline Offline

Activity: 751
Merit: 251


View Profile
February 12, 2016, 09:28:48 PM
 #5

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
watashi-kokoto
Sr. Member
****
Offline Offline

Activity: 682
Merit: 269



View Profile
February 13, 2016, 09:39:54 PM
 #6


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
altcointalk14 (OP)
Sr. Member
****
Offline Offline

Activity: 751
Merit: 251


View Profile
February 24, 2016, 09:32:05 PM
Last edit: February 25, 2016, 02:07:10 PM by altcointalk14
 #7

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!!
watashi-kokoto
Sr. Member
****
Offline Offline

Activity: 682
Merit: 269



View Profile
February 25, 2016, 04:07:15 PM
 #8

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
altcointalk14 (OP)
Sr. Member
****
Offline Offline

Activity: 751
Merit: 251


View Profile
February 25, 2016, 07:52:28 PM
 #9

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://bitcointalk.org/index.php?topic=944596.msg10342157#msg10342157

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!
tspacepilot
Legendary
*
Offline Offline

Activity: 1456
Merit: 1078


I may write code in exchange for bitcoins.


View Profile
February 25, 2016, 08:58:37 PM
 #10

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.
altcointalk14 (OP)
Sr. Member
****
Offline Offline

Activity: 751
Merit: 251


View Profile
February 25, 2016, 09:54:41 PM
 #11

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
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3388
Merit: 6631


Just writing some code


View Profile WWW
February 25, 2016, 10:03:20 PM
 #12

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];

altcointalk14 (OP)
Sr. Member
****
Offline Offline

Activity: 751
Merit: 251


View Profile
February 26, 2016, 12:13:36 AM
 #13

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;
}

achow101
Moderator
Legendary
*
Offline Offline

Activity: 3388
Merit: 6631


Just writing some code


View Profile WWW
February 26, 2016, 12:15:10 AM
 #14

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.

altcointalk14 (OP)
Sr. Member
****
Offline Offline

Activity: 751
Merit: 251


View Profile
February 26, 2016, 12:52:23 AM
 #15

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?
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3388
Merit: 6631


Just writing some code


View Profile WWW
February 26, 2016, 12:55:40 AM
 #16

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.

altcointalk14 (OP)
Sr. Member
****
Offline Offline

Activity: 751
Merit: 251


View Profile
February 26, 2016, 01:05:59 AM
 #17

Thank You!
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!