Post
Topic
Board Development & Technical Discussion
Merits 4 from 2 users
Topic OP
Prime number Bitcoin keypairs - How and why
by
BTCW
on 20/03/2021, 01:30:51 UTC
⭐ Merited by Heisenberg_Hunter (2) ,ETFbitcoin (2)
HOW

First, consider this Bitcoin key pair:

Code:
Private key compressed (wif):
L3ACAgUJquKbnuYUywUqJNo6QACyMZvMvtx7Gt7QrbsrMkBhCDwA

P2PKH Public Address (Legacy):
1HBK1zXfLLJw9GUidvnb5bBVt8GReDnXhj

At a first glance, they look random and nothing special at all. Let's however convert these base58 numbers to hexadecimal, and we get (note that I use only the compressed form):

Code:
Private key (hex):
b136fef8391b4956312a6df2f6dc99b7cf238982dbcfbcb629f4ed6d35671a77

Public Address hash160 (hex):
b175364aaea8ecb515c1779cd00b0c3ba157bb25

Still not impressed? Alright, let's convert them to decimal (ordinary) numbers, so that:

Code:
Private key (dec):
80156543676389067380819750297890580630517839339787739613967701593439506733687

Public Address hash160 (dec):
1013105283100545924034097521935085705519926065957

Decimal numbers are easier for us humans. Do you see it now? These numbers are prime! You can easily verify this by trying to factor the two numbers here, or with programs like Matlab or other programs that can handle large numbers.

These two are only divisible with themselves and 1. In other words, they are prime. How cool is that?


The code

It took me some time to figure out how to produce key pairs like this. Large number factorization is computationally heavy. The pseudo-code works like:

Code:
1. Generate a random 32-byte number

2. If it is prime, go to step 3 - if it is not prime, go back to step 1

3. We have a prime private key; from it, compute the compressed public address, and more specifically its hash160

4. If both the private key and hash160 are prime, we are done - if the hash160 is not a prime, go back to step 1

If anybody is interested, I have the complete code in Python3 with several speed optimizations. Do tell!

On a regular laptop and using CPU only, it takes about 2-10 seconds to produce what I call "a true Bitcoin key pair".


Example output

When executed, the script outputs the following

Code:
==== RESULTS ===================================================

Private Key (32-byte PRIME NUMBER in HEX):
b136fef8391b4956312a6df2f6dc99b7cf238982dbcfbcb629f4ed6d35671a77

Public Address (HASH160 - 20-byte PRIME NUMBER in HEX)
b175364aaea8ecb515c1779cd00b0c3ba157bb25

==== PRIVATE KEY AND PUBLIC ADDRESSES (COMPRESSED ONLY) ========

Private key (WIF):
L3ACAgUJquKbnuYUywUqJNo6QACyMZvMvtx7Gt7QrbsrMkBhCDwA

P2PKH Public Address (Legacy):
1HBK1zXfLLJw9GUidvnb5bBVt8GReDnXhj

P2WPKH-P2SH Public Address (Wrapped):
39PGSGyV2dokiPxBUnsLR1a8N2bE1Hv9h2

Segwit P2SH Public Address (Bech32):
bc1qk96nvj4w4rkt29wpw7wdqzcv8ws40we9pynp28

==== IMPORT IN ELECTRUM WITH ===================================

p2pkh:L3ACAgUJquKbnuYUywUqJNo6QACyMZvMvtx7Gt7QrbsrMkBhCDwA
p2wpkh-p2sh:L3ACAgUJquKbnuYUywUqJNo6QACyMZvMvtx7Gt7QrbsrMkBhCDwA
p2wpkh:L3ACAgUJquKbnuYUywUqJNo6QACyMZvMvtx7Gt7QrbsrMkBhCDwA

(For other wallets: Read the manual)

==== VERIFICATION ==============================================

Paranoid people should use independent and offline software to
confirm that 80156543676389067380819750297890580630517839339787739613967701593439506733687 and
1013105283100545924034097521935085705519926065957 are prime
numbers, and that they are equal to the hexadecimal numbers in
the first paragraph.


WHY

They say that "prime numbers are the atoms of math, and math is the language of the universe."

It is beautiful. It is satisfactory. It is nerdy.

After coming up with this, I use only perfect Bitcoin primes myself.

But does it have any actual use? I'd love your take on it.

Does it add value? (Primes cannot - by definition - be factorized, so no one could ever arrive at your private key by factorization and multiplication [if that's even a thing].)

Are primes handled "better" (whatever that means) when for example signing transactions, resulting in better byte economy for the blockchain?

Is this unsafe? (I think not, according to the prime number theorem (PNT) there should be about 6.54*10^74 primes - a huge number - in the range as defined by the secp256k1 with the ECDSA algorithm. In other words, of all possible private keys, approximately 0.056% are prime, but only a few of these correspond to public addresses whose hash160 happen to be prime too.)

What do you think?