Bitcoin Forum
October 04, 2025, 05:10:27 AM *
News: Latest Bitcoin Core release: 29.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Development & Technical Discussion / Searching for secp256k1 algo in C# that is fast on: September 20, 2018, 04:00:55 PM
I have 32 byte private key that i generate from a function. Now i need to convert into public key both compress and uncompress fast as i generate thousands of addresses in few seconds.

Currently using C# nBitcoin to convert these private keys to public but that library is to slow and only able to convert 1500 addresses in 5 or 6 seconds

looking for a C# code that can do the job faster to any degree    it will help me  


Can C++ code be faster within C# .NET core ?     is it possible to use C++ within Core ?


Shahzad
2  Bitcoin / Development & Technical Discussion / Generating public compressed/uncompressed key from given private key in C# on: September 18, 2018, 06:17:51 PM
I am using C# core 2.2 for below code and i testing code on i5 7th Gen laptop

I was developing a sort of Vanity Generator that can target few characters in the begging and using C# to do so. Using nBticoin library to generate the addresses  but unfortunately it's very very slow.  Here is the code that was generating these addresses. I put comments at the beginning of code block please read those comments

I am using the nBitcoin C# library


//Declared once in global scope
byte[] tempBitcoinAddressArrayWithChecksum2 = new byte[37]


// Part 1.  This part in code converts currentAddress (which is byte array of bitcoin HEX characters) into Bitcoin WIF format       
tmpBitcoinHash256Output = sha256.ComputeHash(sha256.ComputeHash(currentAddress));
Array.Copy(currentAddress, tempBitcoinAddressArrayWithChecksum2, currentAddress.Length);
Array.Copy(tmpBitcoinHash256Output, 0, tempBitcoinAddressArrayWithChecksum2, currentAddress.Length, 4);    //add checksome at end of bitcoin

// Part 2. Create nBitcoin Bitcoin Secret object
BitcoinSecret secretKey = new BitcoinSecret(Base58.Encode(tempBitcoinAddressArrayWithChecksum2));


// Part 3. finally get the compressed and uncompressed public keys
string unCompressedBitcoinAddress = secretKey.PubKey.GetAddress(Network.Main).ToString()
string compressedBitcoinAddress = secretKey.PubKey.Compress().GetAddress(Network.Main).ToString()



I collected statistics for every 5000 random addresses and found following times

Average time took every 5000 addresses processed   =  6.3 seconds
Part 1 of above code took average 0.02 seconds for every 5000 addresses
Part 2 of above code took average 0.3 seconds for every 5000 addresses mainly because of base58 conversion
Part 3 of above code took average 5.5 - 6 seconds for every 5000 addresses

in average for every 5000 addresses processed this is taking 6 - 6.5 seconds   which is way way too slow for me to generate even 3 or 4 character vanity addresses


Now i am looking for following 2 solutions that may help me speed up the process

1. Fast C# Base58 conversion        at the moment this is taking 0.3 seconds       this is second priority i tried many solutions from web nothing works

2. Most important eliminate nBitcoin's BitcoinSecret  object creation from Part 2 and use that WIF string to produce compressed and uncompressed keys directly    any reduction from 5.5 down to around 1 second will be huge boost       looking for a direct C$ code for this

Can a C++ code in C# speed up the processes ?  if yes please suggest any code and how to put it in my .NET core C# code

Also can i use GPU to speed up the number of keys being processed ? 

In any case i need to speed up the 5.5 second 5000 address speed
3  Bitcoin / Development & Technical Discussion / Trying to convert 256 bit random number to WIF on: August 17, 2018, 05:19:15 PM
I want to convert a randomly generated 256 bitcoin address into WIF.   I have following step by step instructions that i am trying to implement into C# but could not do so yet. the biggest problem is conversion of string into base58. Can somebody help me do this


1.) Take a private key (Below is the HEX representation of binary value)
7542FB6685F9FD8F37D56FAF62F0BB4563684A51539E4B26F0840DB361E0027C

2.) Add a 0x80 byte in front of it
807542FB6685F9FD8F37D56FAF62F0BB4563684A51539E4B26F0840DB361E0027C

3.) Perform SHA-256 hash on the extended key
$ echo -n '807542FB6685F9FD8F37D56FAF62F0BB4563684A51539E4B26F0840DB361E0027C' | xxd -r -p | sha256sum -b
7DE4708EB23AB611371BB778FC0C8BDE80394AB2D8704D7129FB5771E2F1730D

4.) Perform SHA-256 hash on result of SHA-256 hash
$ echo -n '7DE4708EB23AB611371BB778FC0C8BDE80394AB2D8704D7129FB5771E2F1730D' | xxd -r -p | sha256sum -b
CD5C4A8E03DFBB0E3AA021C2D74A9EAA43CE4C9CB1B20FC88729A7A5834141CA

5.) Take the first 4 bytes of the second SHA-256 hash, this is the checksum
CD5C4A8E

6.) Add the 4 checksum bytes from point 5 at the end of the extended key from point 2
807542FB6685F9FD8F37D56FAF62F0BB4563684A51539E4B26F0840DB361E0027CCD5C4A8E

7.) Convert the result from a byte string into Base58 to get it into the Base58Check format. This is also known as the Wallet Import Format


Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!