4

I am using bitcoinlib in python to create bitcoin wallet as shown here. My question is that how random private keys are which are generated by bitcoinlib?

For example Alice has private key '5ThisIsMyPrivateKey' which was created by some other program (bitcoin core, coinbase, hitbtc or anyone) and I am using bitcoinlib and I have a wallet for Bob and Bob's private key generated by bitcoinlib can be '5ThisIsMyPrivateKey'? What is possibility of it?

Another question is that is there a possibility of having same public key of two or more private key? I have seen lots of different private key structure when I was looking for information and I found three of examples where private keys starts with "5", "K" and "L" so is it possible that same public address can be created by using either of private key version?

I am still new here at encryption and bitcoin and I am just looking for information.

Thanks for your time.

2 Answers 2

11

When you create a private key, this process is (or at least should be) completely random - meaning that in theory, the probability of creating some specific private key is 1/N where N is the number of possible private keys. There's nothing stopping someone from creating an already created private key, except chance.

A private key is made up of 256 completely random bits. Thus, the number of possible private keys is 2256 (approximately 1077) and the chance of getting a certain exact private key is 10-77. It's hard to overstate how tiny this probability is - for example, it's roughly equal to the number of hydrogen atoms in the observable universe. We can treat this probability as essentially 0.

is there a possibility of having same public key of two or more private key?

Yes, absolutely. There is nothing preventing two private keys from being associated with the same public key - however, the only way of finding such a case would be through brute force (generating keys until you find a pair that match, and as we learnt above bruteforcing 256 bits is essentially impossible. Even doing a birthday attack - where you generate keys until ANY two of the generated match, you will still have to create 10^38 keys before a 50% chance of collision.

Also, if by public key you are referring to bitcoin addresses, then this can very easily be mathematically proven to be true by the pigeonhole principle. There are 2^256 possible private keys but only 2^160 possible addresses - so it's impossible to have each private key generate a unique address.

4
  • You're welcome. Feel free to upvote too if it helped :)
    – mxbi
    Commented Jan 3, 2018 at 23:05
  • 1
    I tried to upvote first but I don't have enough reputation to do it. But I want to tell here that it is really good answer and It helped me a lot to understand more in depth about behind the scene of bitcoin. Commented Jan 4, 2018 at 16:39
  • Am I correct that this probability applies only if there is only one existing address? If we take into account the millions of addresses that currently exists, or perhaps in the future where the number of addresses will increase by millions, would the probability of getting a duplicate address increases? And if someone in the future is intending to search for a duplicate address using a very fast computer, the probability of getting a duplicate would surely increase. I'm not sure if these things will greatly affect or if it will just have less effect but I just want to add this point.
    – d_air
    Commented May 31, 2023 at 20:04
  • @d_air Let's say that there are 1 billion addresses (10^9). This means that you'd have to search 10^77/10^9=10^68 addresses before finding a collision - this is still exceptionally large!
    – mxbi
    Commented Jun 4, 2023 at 21:16
0

A research in 2012 has shown duplicate keys though it doesn't directly apply to your case but there is possibility. You can read details here

https://factorable.net/paper.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.