Wednesday, May 28, 2008

Cool Python way to beat email harvesting bots

This was so cool -I really had to share it. I found this here while reading up about creating Python extensions using swig. The author uses Python list comprehensions along with chr() and ord() to generate contact email addresses.

Suppose your email address was user@somerandomwebsite.com (SPAM THAT !) . Here is what you would do to generate the correct string sequence for this email address.

>> ''.join([chr(ord(c)+2) for c in 'user@somerandomwebsite.com'])
wugtBuqogtcpfqoygdukvg0eqo


Now stick this back into the previous list comprehension as follows

>> ''.join([chr(ord(c)-2) for c in 'wugtBuqogtcpfqoygdukvg0eqo'])
user@somerandomwebsite.com

I guess such a link on your web page would prevent or at least dissuade anyone except an intermediate Python programmer from trying to contact you - which may or may not be what you want !

2 comments:

SedesGobhani said...

The 2nd one works. For the first one I got 'sqcp>qmkcp_lbmkuc`qgrc,amk' instead of 'user@somerandomwebsite.com'.

Raghavan said...

Thanks Red. There was a typo in the 1st one. That should read :

''.join([chr(ord(c)+2) for c in 'user@somerandomwebsite.com'])

and NOT

''.join([chr(ord(c)-2) for c in 'user@somerandomwebsite.com'])