Bitcoin Forum
April 27, 2024, 03:28:15 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: C# or C/C++ code to convert Bitcoin brainwallet to public address  (Read 344 times)
pbies (OP)
Full Member
***
Offline Offline

Activity: 244
Merit: 126



View Profile
June 07, 2023, 04:11:38 PM
Last edit: June 07, 2023, 06:45:21 PM by pbies
 #1

I am looking for C# or C/C++ code to convert Bitcoin brainwallet to public address.

Has anyone written as such?
Can you share the code?

Where eventually to look for libraries to write such a code?

Thank you

BTC: bc1qmrexlspd24kevspp42uvjg7sjwm8xcf9w86h5k
I have 9900K and 1080 Ti, gathering funds for new desktop PC for Bitcoin operations - 14900K and RTX 4090
If you want to be a moderator, report many posts with accuracy. You will be noticed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
apogio
Sr. Member
****
Online Online

Activity: 420
Merit: 945



View Profile WWW
June 07, 2023, 04:19:16 PM
 #2

I am looking for C# or C/C++ code to convert Bitcoin brainwallet to public address.

Has anyone written as such?
Can you share the code?

Where eventually to look for libraries to write such a code?

Thank you

Hello, have a look here: https://github.com/apogio/old-school-bitcoin. It generates a private key along with its public key and its legacy address. It also provides you with the corresponding QR codes. It is not a brainwallet checker, but you could use ideas from this in order to develop what you asked.

Before you check it out though, please consider:

1. It's in Java.
2. Don't rely on this kind of programs (even though I am the one who developed it). Please make sure to use well maintained software wallets.
3. I think I will develop what you asked, just for fun. I will let you know.

pbies (OP)
Full Member
***
Offline Offline

Activity: 244
Merit: 126



View Profile
June 07, 2023, 04:52:52 PM
 #3

Hello, have a look here: https://github.com/apogio/old-school-bitcoin. It generates a private key along with its public key and its legacy address. It also provides you with the corresponding QR codes. It is not a brainwallet checker, but you could use ideas from this in order to develop what you asked.

Before you check it out though, please consider:

1. It's in Java.
2. Don't rely on this kind of programs (even though I am the one who developed it). Please make sure to use well maintained software wallets.
3. I think I will develop what you asked, just for fun. I will let you know.


This could be written in one class in one file.

I rarely used Java.

Need some C/C++/C# solution.

BTC: bc1qmrexlspd24kevspp42uvjg7sjwm8xcf9w86h5k
I have 9900K and 1080 Ti, gathering funds for new desktop PC for Bitcoin operations - 14900K and RTX 4090
apogio
Sr. Member
****
Online Online

Activity: 420
Merit: 945



View Profile WWW
June 07, 2023, 04:59:43 PM
 #4

This could be written in one class in one file.

I disagree! In general it's better using one class / service for each specific task that you want to implement.

The reason my program is split into multiple files, even though it looks like it shouldn't, is because it is much easier to maintain a program that has well-separated functionalities.

Imagine a program where the entropy generation, the printing utils, the type conversion utils,  the qr code generation and everything else is in one file. This is not recommended.

I rarely used Java.

Need some C/C++/C# solution.

Ok! I am sure you can find people here that write code in those languages.

ymgve2
Full Member
***
Offline Offline

Activity: 161
Merit: 230


View Profile
June 07, 2023, 05:29:38 PM
 #5

Brainflayer does it, of course focused on speed instead of readability and modularity
pbies (OP)
Full Member
***
Offline Offline

Activity: 244
Merit: 126



View Profile
June 07, 2023, 06:23:57 PM
 #6

Brainflayer does it, of course focused on speed instead of readability and modularity

Can you share command for brainflayer that it converts brainwallet to public address in Base58Check format?

BTC: bc1qmrexlspd24kevspp42uvjg7sjwm8xcf9w86h5k
I have 9900K and 1080 Ti, gathering funds for new desktop PC for Bitcoin operations - 14900K and RTX 4090
witcher_sense
Legendary
*
Offline Offline

Activity: 2310
Merit: 4313

🔐BitcoinMessage.Tools🔑


View Profile WWW
June 07, 2023, 06:29:02 PM
Merited by pbies (1)
 #7

Here is the list of brainwallet-related tools (implemented in C#/C) that I found in Google:

Brainwallet-style address generator in C
A C# cracker tool for bitcoin brainwallets and other low entropy key algorithms.
Find hidden Bitcoin brainwallets within books and other TXT files (C#)
A proof-of-concept cracker for cryptocurrency brainwallets and other low entropy key alogrithms.(C)

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
PawGo
Legendary
*
Offline Offline

Activity: 952
Merit: 1367


View Profile
June 08, 2023, 09:18:16 AM
 #8

Check project "FinderOuter" (https://github.com/Coding-Enthusiast/FinderOuter)
I am not sure if it has exact functionality you mentioned, but I am 99% sure you will find there all the blocks you need (sha256, pubkey generation, base58 conversion etc).
pbies (OP)
Full Member
***
Offline Offline

Activity: 244
Merit: 126



View Profile
June 08, 2023, 01:25:31 PM
 #9

Solved.

I used NBitcoin libraries and using code like this:

Code:
Key keyU = new Key(ComputeSHA256(line), fCompressedIn: false);
Console.WriteLine(keyU.GetAddress(ScriptPubKeyType.Legacy, Network.Main) + " # " + keyU.GetWif(Network.Main) + " # " + line);

BTC: bc1qmrexlspd24kevspp42uvjg7sjwm8xcf9w86h5k
I have 9900K and 1080 Ti, gathering funds for new desktop PC for Bitcoin operations - 14900K and RTX 4090
BlackHatCoiner
Legendary
*
Online Online

Activity: 1498
Merit: 7292


Farewell, Leo


View Profile
June 08, 2023, 08:23:51 PM
 #10

Question of mine: how can you do this in C? Not sure about C++, but in C the longest integer value can be minimum 64 bits (long long). In most systems, it's 64 bits, but I'm quite sure in no system it exceeds 256 bits, which are required for SHA-256. (Also, this)

Is there a known library that lets you do some sort of "tricks" with the processor?

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
PowerGlove
Hero Member
*****
hacker
Offline Offline

Activity: 508
Merit: 3974



View Profile
June 09, 2023, 04:09:51 AM
 #11

Question of mine: how can you do this in C? (...)
You mean how can you define a 256-bit data type?

The general idea is that you express the number in a different base (depending on what data types you do have available). For example, if all you had was (let's say) unsigned char (assume that CHAR_BIT == 8), and you wanted an unsigned 32-bit data type, then you could simulate one with a struct (and your own functions to implement arithmetic and logic operations) by thinking in terms of a 4-digit number in base 256, rather than a 32-digit number in base 2. Same thing extends to thinking of a 256-bit number as a 16-digit number in base 65536, or as a 4-digit number in base 2**64, etc.

There are variations on this technique, but that's the basic idea.

Here's one implementation (in C, and assembly): https://github.com/piggypiggy/fp256.

And here's (a piece of) a more specialized implementation from libsecp256k1 (52-bit limbs instead of 64-bit ones): https://github.com/bitcoin-core/secp256k1/blob/master/src/field_5x52_impl.h.
Coding Enthusiast
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
June 09, 2023, 04:58:43 AM
 #12

Check project "FinderOuter" (https://github.com/Coding-Enthusiast/FinderOuter)
I am not sure if it has exact functionality you mentioned, but I am 99% sure you will find there all the blocks you need (sha256, pubkey generation, base58 conversion etc).
Almost all the code used in FinderOuter is heavily specialized to perform special tasks required for recovery. Considering how it doesn't have a recovery option for brainwallets, it is not useful for OP. (I haven't seen any demand for brainwallet recovery option to add it to FinderOuter)

If you want general implementation of different algorithms like SHA256, ECC, etc. my library Bitcoin.Net is more useful.
Although I should add that if the goal is to "recover" a brainwallet, any "general purpose library" is very inefficient.

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
BlackHatCoiner
Legendary
*
Online Online

Activity: 1498
Merit: 7292


Farewell, Leo


View Profile
June 10, 2023, 12:59:45 PM
 #13

For example, if all you had was (let's say) unsigned char (assume that CHAR_BIT == 8), and you wanted an unsigned 32-bit data type, then you could simulate one with a struct (and your own functions to implement arithmetic and logic operations) by thinking in terms of a 4-digit number in base 256
Not sure I understand. You're saying that if I wanted a 32-bit data type, and my only data type available was unsigned char, I could design 32-bit data type by defining a struct as following?
Code:
struct integer_type{
    unsigned char byte_1;
    unsigned char byte_2;
    unsigned char byte_3;
    unsigned char byte_4;
}

And so, if I wanted to store integer 2^32-1, I'd fill in each of these fields with 255? Theoretically, I can extend this to unlimited bits long data type, but various functions from the standard library won't work, and I'll have to rewrite them myself (i.e., printf), which besides difficult, is beyond simple to read, whereas in C# if I'm not mistaken, such capabilities exist already.

I'm just curious why I can't define a 256-bit or x-bit data type in C.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
PowerGlove
Hero Member
*****
hacker
Offline Offline

Activity: 508
Merit: 3974



View Profile
June 11, 2023, 12:35:48 AM
Merited by BlackHatCoiner (8), ABCbits (2), Cricktor (1)
 #14

Not sure I understand. You're saying that if I wanted a 32-bit data type, and my only data type available was unsigned char, I could design 32-bit data type by defining a struct as following?
Yup, but that would only get you like 1% of the way there (defining the struct, that is; the bulk of the work is in defining the operations).

And so, if I wanted to store integer 2^32-1, I'd fill in each of these fields with 255?
Exactly, (255*256**3) + (255*256**2) + (255*256**1) + (255*256**0) == (1*2**31) + (1*2**30) + ... + (1*2**0) == 2**32-1 (brackets for readability).

Theoretically, I can extend this to unlimited bits long data type (...)
Yep, but if you're looking for arbitrary precision, then it's worth studying something like GMP.

(...) but various functions from the standard library won't work, and I'll have to rewrite them myself (...)
That's right.

(...) whereas in C# if I'm not mistaken, such capabilities exist already.
Yup, I'm not a big C# guy, but it has BigInteger (in the System.Numerics namespace, since .NET Framework 4.0, I think).

I'm just curious why I can't define a 256-bit or x-bit data type in C.
That's coming in C23. I'm not sure what value BITINT_MAXWIDTH will take on most compilers, but assuming it's large enough, then you'll be able to write _BitInt(256), or unsigned _BitInt(256), etc.

I can't really say that I'm a fan of this approach (especially in a systems programming language like C). Every time something is made easier for people, there's a corresponding drop in the skill level of the average practitioner. I'm not a sadist, but I do think there's harm in a situation where programmers can make heavier and heavier lifts, but have less and less idea of how things actually work.
pooya87
Legendary
*
Offline Offline

Activity: 3430
Merit: 10505



View Profile
June 11, 2023, 03:53:03 PM
 #15

I'm just curious why I can't define a 256-bit or x-bit data type in C.
You can do that in any language by constructing something (ie. struct in c#) in that language that consists of multiple instances of primitive types that store the bits. For example if you want to create a 128-bit data type you'd create a struct holding two 64-bit integers on x64 or 4 32-bit integers on x86 machine. You can see how it is done in C for a 256-bit integer with 4x 64-bit chunks and 8x 32-bit chunks (of course implementation is specialized for use in ECC).
Ignoring the fixed length and the specialization of the implementation, the above code is essentially what the Biginteger class in dotnet (C#) does. That is using an existing primitive type (UInt32) to hold bits/chucks and performing the arithmetic on them.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
ymgve2
Full Member
***
Offline Offline

Activity: 161
Merit: 230


View Profile
June 11, 2023, 04:41:31 PM
 #16

You can define any data type you like in C/C++ with structs/classes, they just aren't native data types and you have to implement the operations on them yourself. With operator overloading in C++ you can even have them act like native numbers with + and - etc.
pbies (OP)
Full Member
***
Offline Offline

Activity: 244
Merit: 126



View Profile
June 14, 2023, 11:22:51 AM
 #17

Question of mine: how can you do this in C? Not sure about C++, but in C the longest integer value can be minimum 64 bits (long long). In most systems, it's 64 bits, but I'm quite sure in no system it exceeds 256 bits, which are required for SHA-256. (Also, this)

Is there a known library that lets you do some sort of "tricks" with the processor?

You don't need any additional libraries.

You just define the data structure as array of bytes (byte[]), with known length and operate on it as it is.

Eventually you can make sth called union, where you define set of bytes or other type data and put it in one structure, where the data is one after another in memory.

BTC: bc1qmrexlspd24kevspp42uvjg7sjwm8xcf9w86h5k
I have 9900K and 1080 Ti, gathering funds for new desktop PC for Bitcoin operations - 14900K and RTX 4090
PawGo
Legendary
*
Offline Offline

Activity: 952
Merit: 1367


View Profile
June 14, 2023, 11:24:27 AM
 #18

I'm just curious why I can't define a 256-bit or x-bit data type in C.
You can do that in any language by constructing something (ie. struct in c#) in that language that consists of multiple instances of primitive types that store the bits.
(...)
Ignoring the fixed length and the specialization of the implementation, the above code is essentially what the Biginteger class in dotnet (C#) does.

It is a bit complicated (https://stackoverflow.com/a/54815033) bit you may also use 128 bit type. Of course in terms of performance many depends on the CPU architecture and not always using 64 bit type could be faster than using 32 bit type - could be opposite if machine is 32bit.

And of course BigInteger could be the solution, in c# or java.

pooya87
Legendary
*
Offline Offline

Activity: 3430
Merit: 10505



View Profile
June 15, 2023, 04:51:47 AM
Merited by ABCbits (1)
 #19

You just define the data structure as array of bytes (byte[]), with known length and operate on it as it is.
FWIW Using bytes (ie. 8-bit unsigned integers) is the least efficient way of storing bits and also for performing arithmetic since after all you are performing them on 8 bits at a time whereas bigger primitive types exist that can be used to perform arithmetic on more bits like 32-bit integers ({U}Int32) and 64-bit integers ({U}Int64).

Of course in terms of performance many depends on the CPU architecture and not always using 64 bit type could be faster than using 32 bit type - could be opposite if machine is 32bit.
Regardless of the architecture, using 64-bit types may not always be the best option considering that you have to handle overflow and specifically the multiplication is going to be tough if you are using a 64-bit chunks.
This is why in libsecp256k1 something like the field element is implemented using 64-bit integers but only 52 bits of each limb is used, the remaining 12 bits are there to handle overflow. That is radix 252 representation of the 256-bit integer.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
BlackHatCoiner
Legendary
*
Online Online

Activity: 1498
Merit: 7292


Farewell, Leo


View Profile
June 15, 2023, 02:39:20 PM
 #20

Every time something is made easier for people, there's a corresponding drop in the skill level of the average practitioner.
Hmm. I don't think that's enough of an argument to not have standard replacements of this kind. To put it this way: if the average practitioner wants to write a program with 256-bit integers, and acknowledges he's incapable of maintaining that in C, won't he just switch to an alternative, like Python?

You can do that in any language by constructing something (ie. struct in c#) in that language that consists of multiple instances of primitive types that store the bits. For example if you want to create a 128-bit data type you'd create a struct holding two 64-bit integers on x64 or 4 32-bit integers on x86 machine.
Sure, it's possible, but to rephrase my question: why isn't it standard already? I mean, the last C standard was published in 2017, long after Big Integers became a need. And still, the largest standard integer you can define is 64-bits long.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
Pages: [1] 2 »  All
  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!