Wednesday 3 October 2012

Hide email addresses from email scanners

I have always wondered how spammers can find my email adress. Do they just send mail to random adresses and hope it will arrive. My idea was that there were scanners that search the web and find e-mail adresses on random web sites.

So I wanted to hide the e-mail adress in the HTML code somehow, but still keep the original function of a mailto: link.

Take this simple Javascript.

function mejl(adress) {
window.location = "mailto" + unescape("%3A") + decode(adress);
}

It can be used on a normal link like this:

<a href="javascript:mejl('znkv.sbb@ubzr.fr')">mail me</a>

As you can see there is my e-mail adress encoded using ROT-13, znkv.sbb@ubzr.fr. It also looks like a working e-mail adress. So an e-mail scanner might pick it up and think it is a real adress. The decode() function can be replaced with any de-randomizing function you can come up with yourself. But here's the ROT-13 decoder.

var rot13map;

function rot13init()
{
  var map = new Array();
  var s   = "abcdefghijklmnopqrstuvwxyz";
 
  for (i=0; i<s.length; i++)
    map[s.charAt(i)]            = s.charAt((i+13)%26);
  for (i=0; i<s.length; i++)
    map[s.charAt(i).toUpperCase()]    = s.charAt((i+13)%26).toUpperCase();
  return map;
}

function decode(a)
{
  if (!rot13map)
    rot13map=rot13init();
  s = "";
  for (i=0; i<a.length; i++)
    {
      var b = a.charAt(i);

      s    += (b>='A' && b<='Z' || b>='a' && b<='z' ? rot13map[b] : b);
    }
  return s;
}

function mejl(adress) {
    window.location = "mailto" + unescape("%3A") + decode(adress);
}

No comments:

Post a Comment