Bitcoin Vanity Address generator from scratch in Python.

Deepak Prajapati
3 min readJun 21, 2021

What is Bitcoin Vanity Address ?

BTC vanity addressess are a unique base58 string which are used as a identifier for the transfer of Bitcoin if transaction is valid.

Pre-requisite:

Basic knowledge of any Object Oriented Programming Language (Python, CPP, Java, JavaScript, etc).

How to develop BTC vanity address generator ?

Bitcoin Vanity Address are generated with the help of a curve known as Elliptical Curve. An address is generated from Public key(PK). PK is a product of Private key(SK) and Generator Point(GP). SK is a random 256-bit (32-byte) cryptographically generated number. GP is a standard point (location) on curve defined by the Bitcoin inventor. GP has x co-ordinate and y co-ordinate. In short, PK = SK * GP.

The curve which BTC uses for generation of PK is show below.

Elliptical Curve with equation y2 = x3 + 7
y2 = x3 + 7

When we multiply a number with a point of curve generally its not possible to directly multiply two different data types. So, we need to override the multiplication defination according to our own requirements. But how the multiplication is done ? Bascially, we need to add generator point sk times.

For example:

Let sk = 5, gp = 2

pk= 5 * gp

pk = (2+(2+(2+(2+2)))) = 10

But one can also say 5*2 is also 10. These are just number’s when we talk in case of points the results are not like simple multiplication. When add 1st and 2nd point, we get the result 3rd point and so on….

Before proceeding to wallet address, we need to compress public key. PK have x coordinate and y coordinate. Check whether the y coordinate is even or odd. If it is even then we need to add “02” as pefix to x coordinate (hexadecimal format) else add “03”.

Once, we get our compressed public key we need to perform few operations to successfully convert PK to wallet address. The operations are as follows :

  1. Hash compressed pk (bytes format) using SHA256 and get the hashed key in byte format.
  2. Again hash the hashed key (obtained from step 1) using RIPEMD-160 and get the new hashed key in byte format.
  3. Add “00” as prefix to the hex of newly hashed key (obtained from step 2).
  4. Create a copy of 3rd step result for further use.
  5. Hash 3rd step results (bytes format) using SHA256 and get the hashed key in byte format.
  6. Again hash the hashed key (obtained from step 5) using SHA256 and get the hashed key in byte format.
  7. Convert the results of 6th step into hex format and get first 4 bytes (8 letters). Add as postfix to the copy which we create in step 4.
  8. Pass the result of step 7 through base58 format.
  9. Congrats, You have successfully create your first BTC wallet address.

To verify whether you have create correct wallet address use https://www.bitaddress.org/

BTC never uses RSA generated Public key and Private Key for security purpose.

For code please visit to GitHub:

Bitcoin-Vanity-Address

--

--

Deepak Prajapati
0 Followers

A mechanical student who tries programming.