Title: Go lang - Create a random Bitcoin address Post by: Jude Austin on March 28, 2015, 04:37:12 PM Hello,
I am trying to generate a random Bitcoin address using Go lang but my current setup isn't very random, lol. This is the current output from the code below: Code: 000000000000000000000000000000000000000000000039bebc16a4f5c1002e Code: rint := rand.Intn(9223372036854775807) Any help would be appreciated and most likely rewarded. Title: Re: Go lang - Create a random Bitcoin address Post by: LewiesMan on March 28, 2015, 04:55:19 PM Looks random to me, I don't see any indication of uniformity...unless I'm missing something?
Title: Re: Go lang - Create a random Bitcoin address Post by: CIYAM on March 28, 2015, 04:57:03 PM Perhaps the issue is the zero padding (although that seemingly has been done on purpose and I don't grok Go)?
Title: Re: Go lang - Create a random Bitcoin address Post by: Jude Austin on March 28, 2015, 05:01:03 PM Yes, it is all of the 0 padding.
If you take any random address you find on the internet, I can almost guarantee the private key in hex won't start with all of those 0's. That is what I am trying to eliminate. Title: Re: Go lang - Create a random Bitcoin address Post by: CIYAM on March 28, 2015, 05:04:04 PM Then why are you doing this?
Code: padded := make([]byte, 32) (I am assuming that is what gives you the zeros along with your widening to 64 bit ints?) If each "random" is only 4 bytes (32 bits) then you'd need to use 8 such random numbers for one 256 bit value. Unfortunately I have never written any code in Go so can't give you "the answer" but what you are basically going to have to do is work out how to put together the smaller random numbers into the 256 bit value (piece by piece). Title: Re: Go lang - Create a random Bitcoin address Post by: Jude Austin on March 28, 2015, 05:10:54 PM Then why are you doing this? Code: padded := make([]byte, 32) (I am assuming that is what gives you the zeros) This could be the issue but I think the real issue is the size of the integer I am converting to bytes. Wouldn't it be more random to generate a random byte string than use big integers to convert to bytes? The outcome I would like to see is no uniformity between each generated private key, like now there is: 00000000000000000000000000000000000000000000003b41b7a14a1db1f2c8 and then 00000000000000000000000000000000000000000000003b8f1d236b25aef01a I want: 219380471027f01298401284012a74801247012479120947102947102947102947120f and then 123969348182361276387129388129u0d030498092f9102901920391283778d8379287 Title: Re: Go lang - Create a random Bitcoin address Post by: Jude Austin on March 28, 2015, 05:16:16 PM Then why are you doing this? Code: padded := make([]byte, 32) (I am assuming that is what gives you the zeros along with your widening to 64 bit ints?) If each "random" is only 4 bytes (32 bits) then you'd need to use 8 such random numbers for one 256 bit value. Unfortunately I have never written any code in Go so can't give you "the answer" but what you are basically going to have to do is work out how to put together the smaller random numbers into the 256 bit value (piece by piece). No problem, you are helping me by talking it out and I appreciate it! Title: Re: Go lang - Create a random Bitcoin address Post by: CIYAM on March 28, 2015, 05:18:39 PM The 3b prefix is interesting because 3b41b7a14a1db1f2c8 is 18 characters (you'd expect 16 if it was a 64 bit value being displayed in hex).
My guess is that you also have something going on with your outputting. Title: Re: Go lang - Create a random Bitcoin address Post by: Jude Austin on March 28, 2015, 05:28:17 PM The 3b prefix is interesting because 3b41b7a14a1db1f2c8 is 18 characters (you'd expect 16 if it was a 64 bit value being displayed in hex). My guess is that you also have something going on with your outputting. Probably, hmm. I wish I knew more about Go and this data in general. I have a Python script that does exactly what I want but it's slowwww, like 2 keys a second. I would really like to modify VanityGen as it is optimized for speed. Title: Re: Go lang - Create a random Bitcoin address Post by: tacotime on March 28, 2015, 07:04:19 PM DON'T use your own cryptographic randomness source. DO use ecdsa.GenerateKey and crypto/rand.
https://github.com/monero-project/urs/blob/master/messagesign.go#L46-L82 Looping that would be naive because continual crand calls can be expensive... if you're trying to vanity gen, I would use BIP32 and just continually derive new addresses from a master seed until you found the one you want. https://github.com/btcsuite/btcutil/tree/master/hdkeychain https://github.com/btcsuite/btcwallet/tree/master/waddrmgr Title: Re: Go lang - Create a random Bitcoin address Post by: Jude Austin on March 28, 2015, 07:21:33 PM DON'T use your own cryptographic randomness source. DO use ecdsa.GenerateKey and crypto/rand. https://github.com/monero-project/urs/blob/master/messagesign.go#L46-L82 Looping that would be naive because continual crand calls can be expensive... if you're trying to vanity gen, I would use BIP32 and just continually derive new addresses from a master seed until you found the one you want. https://github.com/btcsuite/btcutil/tree/master/hdkeychain https://github.com/btcsuite/btcwallet/tree/master/waddrmgr TacoTime, Thank you! How would I implement this in my current script? I am not necessarily trying to vanity gen I am trying to create new addresses as quickly as possible and have them be as random as possible. The reason I want to use Go is because I have seen a considerable difference in the speed. C# is pretty slow, 2-3 keys a second, same with Python. Go seems to be considerably faster, C would probably be the best. Title: Re: Go lang - Create a random Bitcoin address Post by: lalaisen on March 28, 2015, 11:16:12 PM I want to have a good BTC address . It's easy to remember. How to create it ?
Thanks a lot ! Title: Re: Go lang - Create a random Bitcoin address Post by: tacotime on March 29, 2015, 04:08:39 PM TacoTime, Thank you! How would I implement this in my current script? I am not necessarily trying to vanity gen I am trying to create new addresses as quickly as possible and have them be as random as possible. The reason I want to use Go is because I have seen a considerable difference in the speed. C# is pretty slow, 2-3 keys a second, same with Python. Go seems to be considerably faster, C would probably be the best. Uh Code: for someCondition { Title: Re: Go lang - Create a random Bitcoin address Post by: Jude Austin on March 29, 2015, 04:27:10 PM TacoTime, Thank you! How would I implement this in my current script? I am not necessarily trying to vanity gen I am trying to create new addresses as quickly as possible and have them be as random as possible. The reason I want to use Go is because I have seen a considerable difference in the speed. C# is pretty slow, 2-3 keys a second, same with Python. Go seems to be considerably faster, C would probably be the best. Uh Code: for someCondition { Hey, thank you! I actually figured it out. I just generated a 64 char random string using hex characters and then used hex.decode string to get the private key from bytes. Here is the output after my changes, a lot more random, the 6 digits at the end are a loop counter: Code: 4aeaaaec1b84ef3015c4ee1d0f094facd02536205ae819276e38f74c7a4605b6 676651 |