I'm now working at small tool, which purpose is to calculate difficulty (like number of attempts) of getting vanity address, like vanitygen (https://github.com/samr7/vanitygen) does. I've read some materials (https://en.bitcoin.it/wiki/Vanitygen#Difficulty_of_finding_a_vanity) and now i'm wondering about exact algorithm of how such calculation must be proceeded. There is no precise answer in the article at bitcoin.it wiki, so a look through the sources of vanitygen and ended up with some very basic ideas:
- All addresses are in a nutshell base58 numbers which can be converted to biginteger if needed.
- There is one final "biggest" address (like biggest number in the end of some range)
- Vanity address is any address from the range of addresses (if we think about them as numbers), that starts with specific pattern.
So what is the best way of finding difficulty of getting specified vanity address? I ended up with such idea:
- Find the biggest possible address and convert it to bigint.
- Find addresses range for given vanity pattern. First of all find the biggest possible address in the range by adding z to the end of the pattern while it is smaller than biggest possible address. Then to get smallest address in range i decided to add 1 (base58 representation for 0) to the vanity patter and i failed to determine when i must stop. Clearly address could not be longer than 34 symbols, but when i must stop? I think that i must take length of the biggest address in the range and that will be the same length for the smallest. But please, correct me if i'm wrong.
- When we have range of addresses, we can calculate it's length by subtracting smallest one from biggest one and then divide biggest possible address by range length and the result will be our difficulty.
So is it all correct? What shall i do when pattern starts with "1"?
What additional materials you can suggest to read?