Sunday, February 1, 2015

So today Google Earth are putting out their promotion for Google
Earth Pro (which is $400 value). It's my free Sunday without any
homework so yeah i'm making an automatic script to auto register for
this product.

The idea to just to use the aliases of each Gmail in order to keep registering without getting new email. What alias is? So let's say you have an email address like abc@gmail.com, Gmail allows you to use aliases such as a.bc, a.b.c, ab.c in order to alternate for your main inbox. Whenever an email is sent to those alias inboxes, you can receive, read and reply from your own inbox abc@gmail.com

Taking advantage of it, I reuse my own class method to generate the alias it. It seems to be easy but th algorithm is a little bit confusing at first for me. So let's do a simple counting problem.

So there is a (x - 1) dots in total. Because dot can just be "on" or "off" so let consider them as binary string. Eg: 101 for a.bc.d . So in order to count how many aliases we have we just can simply count how many binary strings that we can generate from (n -1) chars. Since binary can only be represented as 1 or 0, so we have (n-1)^2 for the number of binary string. Wait, I forgot, let's exclude 0000 which is the original email address. So the total is (n-1)^ - 1. That's the counting and idea part. How can we turn it into python code?

Pretty much we just need to generate the list of that binary string first. There is a nice lib that can help which is itertools. What I did was :

lst = map(list, itertools.product([0, 1], repeat=len(username)-1))

Now we need to map each binary character into it corresponding position in the original username. We can iterate 1 by 1 and then insert the dot into the corresponding position in the username. 2 things to keep in mind that the first dot starts at index + 1 and the last dot ends at len-1. The second thing is that when you insert a dot, the original length changes so you need to keep track of the length of the string.

All put together, you can find my code at: https://github.com/nguyenph88/Google-Earth-Pro-Auto-Register/

Not sure when this promotion ends but I've created a hundred of licences so hit me up if you still need one :)