Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Maus0728 on September 05, 2020, 12:56:19 PM



Title: Is it possible to simulate bitcoin address using C#?
Post by: Maus0728 on September 05, 2020, 12:56:19 PM
Hey greetings,

I've been slowly reading the book of Andreas Antonopolous and currently reading chapter 4 - keys addresses and recently came across the thread created by @webtricks about How Bitcoin Addresses are generated? Understand the Math behind Bitcoin (https://bitcointalk.org/index.php?topic=5223167.0).

Is it possible to create a similar bitcoin address generation using C# programming language in visual studio from a console? I came across with this idea because I am currently enrolled in an online class and it happens that we're using C# programming language in our subject and also have the willingness to learn how these bitcoin addresses are generated from scratch.

What are the requirements to create similar programming just like what webtricks did before in his project? Any recommended readings?


Title: Re: Is it possible to simulate bitcoin address using C#?
Post by: hatshepsut93 on September 05, 2020, 01:06:49 PM
"Simulate" is not the right word here, you are asking how to generate a real Bitcoin address in C#. You can use any programming language available, they are all capable of doing this task.

Generating Bitcoin address requires cryptographic hash function utilities and elliptic curve utilities, though webtrics implemented some elliptic curve functions from scratch in his example. Generally, it's a bad practice to implement something that has already been done and is freely available in forms of libraries, unless done for educational purposes.

So, the simple approach would be to import all the functions that you need, and just assemble your wallet generation function with them.

You can also look for existing C# implementations of it, for example here (https://bitcointalk.org/index.php?topic=5224578.msg53807731#msg53807731).


Title: Re: Is it possible to simulate bitcoin address using C#?
Post by: OmegaStarScream on September 05, 2020, 01:10:51 PM
Take a look at NBitcoin's[1] library, you can either call it[2] or check the source code to see how is it done from scratch.

[1] https://github.com/MetacoSA/NBitcoin
[2] https://programmingblockchain.gitbook.io/programmingblockchain/bitcoin_transfer/bitcoin_address


Title: Re: Is it possible to simulate bitcoin address using C#?
Post by: Maus0728 on September 05, 2020, 01:29:24 PM
WOW! Thank you @hatshepsut93 and @OmegaStarScream for recommending some resources. This can significantly help boost my learning curve between the use of C# as well as learning the algorithm involved in this bitcoin generation address.

I'll ask questions here if there are any issues I encountered throughout the process.  :)


Title: Re: Is it possible to simulate bitcoin address using C#?
Post by: tbct_mt2 on September 05, 2020, 03:39:37 PM
To get a bitcoin address, you need to have a public key. To have a public key, you need to have a private key. You can not find them in the backward steps.

Private key (Eliptic Curve Multiplication) - Publick Key (Hash Function) - Address
k - K - A (irreversible)
And K = k * G

What you ask is the reverse math of the formula and it is impossible.

You can see the explanation for Eliptic Curve at https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch04.asciidoc#elliptic_curve

https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch04.asciidoc


Title: Re: Is it possible to simulate bitcoin address using C#?
Post by: pooya87 on September 06, 2020, 05:01:16 AM
What are the requirements to create similar programming just like what webtricks did before in his project? Any recommended readings?

the topic you shared already contains good information for you to read. also if you want to experiment you can "translate" the code in that topic to c# which isn't really that hard to begin with. if you use .Net Framework then you'll have access to RIPEMD160 and SHA256 and the ECC code is in that topic. BigInt becomes BigInteger (found in System.Numerics) and the points such as G have to be defined as a "struct" that contains 2 BigIntegers (x and y).
if you use .Net Core then you won't have RIPEMD160 anymore but you can copy it from any crypto library or even .Net Framework source code itself (link (https://referencesource.microsoft.com/#mscorlib/system/security/cryptography/ripemd160managed.cs))