Having Fun With Bitcoins: Vanity Bitcoin Address Generation

This article will hopefully give a bit of background around bitcoins and Elliptic Curve Cryptography (ECC), and has a bit of fun with the…

Having Fun With Bitcoins: Vanity Bitcoin Address Generation

This article will hopefully give a bit of background around bitcoins and Elliptic Curve Cryptography (ECC), and has a bit of fun with the creation of addresses which have special sequences.

Please note that you cannot reverse a Bitcoin public key into a private key (well, you could, but it would cost you trillions and trillion and trillions of dollars and more to do it).

There are demos here and here.

Having fun with bitcoins

While many see Bitcoin as a way to make (or lose) money. I see the beauty of the mechanism, and how well it has been crafted. To me, the beauty of the cryptography amazes me, and in the way that the Bitcoin network is still going strong. It was started with a genesis block, and the mechanism has purred along for over nine years. Okay, it’s consuming the energy of a small country, but it has, at least, managed to get an infrastructure up-and-running, and which has some worth. So let’s have a bit of fun with Bitcoins.

So did you know that, if you have the processing power, you could generate a Bitcoin address with a name in it? So, I could have:

1b1llbitcoinxVGKLyNGAobvpDfJYDbsh1

These addresses are defined as a vanity addresses, and are not random. Unfortunately to generate the one above, would cost me more money than I have, as I’d have to search for the required private key which would generate this almost unique public key. But if you do have the money and computing power, you can generate some strange Bitcoin addresses.

So who was the weirdest Bitcoin address? Well one of the longest is “Embarressable

And at 11 characters we have “DETACHABLE” … in upper case [link]:

And gphuddle.org managed to get [link]:

Others have even managed to create a palindrome (an address which is the same when read from the start to end, or the end to the start) [link]:

And another person generated an all upper case address [link]:

The Method

With Bitcoins, we generate a 256-bit private key (n) and use a point on the elliptic curve (G). The public key P is then n×G, and the signature of this is used to generate the Bitcoin address. The following illustrates the process:

If we have enough processing power we can search for private keys which would generate an output address which would have a required character sequence in it. In the program on this page we generate private key and then the public one, and see if the required sequence is contained in the Bitcoin address. If it is not, then we increment the private key by one, and then try again.

A sample run shows the searching for a sequence of “aa”. It can be see that “aa” exists in the generated public Bitcoin address (spaces have been added around the sequence) [sample run]:

Addresses tried ... (just showing first six characters of address)
1MqVCg 18L1Sy 1BLUEh 1MQVFZ 1nA3d6 1AT81f 1DJ9kQ 12RYEK 1CWUtx 1AcDgP 12bxD3 1KNdgg 19xxHn 1885zi 1JzbWn 19ui1w 1J9RVM 1CoaMd 1FxD87 1DGSKJ 1QHeQr 16kRHz 16eNtm 1Avfbd 1DmiAA 1GCPdQ 12ANbh 1C3RWL 14TzuR 14aBU5 1Mzfpm 127kZq 1C1uGu 17G8C1 1H1W2V 14kJku 1HRazj 1NhUEJ 1PL5c9 1PktPP 16Tdks 14XbXN 1FjnPf 1GhHqE 18P4PJ 15MsvM 1DtRJ5 1H2DVm 1Lh2xC 18RCxL 124C2k 17updw 1FVA5n 1CLjQb 15JUkZ 1J9g8a 13Y1Lv 1tJkk6
Public Bitcoin address is 1tJkk66uYRRyaaEyr6Yz9XB1NwrgxN9Mv
Private Bitcoin address is: 1291049162141473901904148853179377639061071336882801200545944876355160619226

It should be noted that Bitcoin addresses always start with a “1” and are created with Base 58 characters. If you are interested in how Bitcoin addresses are created click [here].

If I use a program which does not have limits on the number of keys search, and search for “b1L”, the result is:

Public Bitcoin address is: 1HpuY2st1bUDq9pxE4d8ajzJR1b1LNBdF
and the associated private key is:
4939905350059000420219188404344301855642743657175451
6193252594725833234851243

As we are using Base-58, we replace an ‘i’ for ‘1’, and an ‘o’ for a ‘0’

The following is an outline (and based on [code]:

import random
import ecdsa
import hashlib
from ecdsa.util import string_to_number, number_to_string
from bitcoin import *
# secp256k1, http://www.oid-info.com/get/1.3.132.0.10
_p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2FL
_r = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141L
_b = 0x0000000000000000000000000000000000000000000000000000000000000007L
_a = 0x0000000000000000000000000000000000000000000000000000000000000000L
_Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798L
_Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8L
curve_secp256k1 = ecdsa.ellipticcurve.CurveFp(_p, _a, _b)
generator_secp256k1 = ecdsa.ellipticcurve.Point(curve_secp256k1, _Gx, _Gy, _r)
oid_secp256k1 = (1, 3, 132, 0, 10)
SECP256k1 = ecdsa.curves.Curve("SECP256k1", curve_secp256k1, generator_secp256k1, oid_secp256k1)
ec_order = _r
curve = curve_secp256k1
generator = generator_secp256k1

def get_key(privkey,search_for):
count = 0
address = ''
print "Addresses tried ... (just showing first six characters of address)"
while not search_for.lower() in address.lower():
privkey += 1
pubkey_point =fast_multiply(G, privkey)
address = pubkey_to_address(pubkey_point)
print address[:6],
count += 1
if (count>99):
return 0,0
return address,privkey
seq="aa"

privkey = random.randrange(2**256)
address,privkey=get_key(privkey,seq)
if (address==0):
print "Could not find sequence. Need a cluster!"
else:
print "\n\nPublic Bitcoin address is",address
print "Private Bitcoin address is:",privkey

Split Vanity Bitcoin Address

n split vanity address generation, Bob wants a vanity Bitcoin address with a defined sequence, and so generates a key pair (a,A), and publishes A (his public key) to the Trent. Bob then asks for Trent to generate a key pair (b,B) and which will produce a given hash which has defined letters. Trent then searches for the best solution. If found, Trent gives Bob the solution of (b,B) and Bob’s private key becomes (a+b). The address will then be the hash of (A+B) … this is the public Bitcoin address. This works because of the way the elliptic curve works, where we can add private key:

A=a×G

B=b×G

A+B=a×G+b×G=(a+b)×G

The operation we have is an addition of the keys, and where Bob simply adds aa and bb to find the private key for the published Bitcoin address (Hash(A+B)).

The following outlines the process:

The following shows that the addition of (a+b) is the same as the generation of the public key (A+B):

Private Key (a) 86061879872531449951982497796959448028218381820041432789293827894874333168061
Private Key (B) 67049838517580778648042191759706328871467476377487957098163453293050470005128
Public Key (A) (52281756525516179214864400768152603516588884663484649962958165358048515611229L, 3506106637400073941700097757900439597340138321945710007917595359770824320067L)
Public Key (B) (92274947923957043323674480256700292927552770224860750077123722920663254277413L, 111720110584941718181062835691990151475626279782674278759154810677066455066531L)
Public key (Hash(A+B)): 1PkuH4XSqSrgnb7Uegxfh8ebRXYjP9CA49
Public key (Pub(a+b)): 1PkuH4XSqSrgnb7Uegxfh8ebRXYjP9CA49

Conclusions

There are demos here and here.

I love Bitcoins, Ether, IOTA, and all the other crypto currencies. Not for spending money, but for the way they work. It has been a journey to understand how they work, but I now understand them fully, and you must give credit to a system which has not been supported by any government or standards agency, but has managed to get it self up-and-running, and is still going strong. The beauty and simplicity of elliptic curve methods leaves me in awe. We have a new world at our finger tips. Forget the old world … tokenization is the future!