Skip to content

Instantly share code, notes, and snippets.

@Xophmeister
Created July 11, 2012 10:09
Show Gist options
  • Save Xophmeister/3089424 to your computer and use it in GitHub Desktop.
Save Xophmeister/3089424 to your computer and use it in GitHub Desktop.
Extreme E-Mail Obfuscation
<html>
<head>
<title>Extreme E-Mail Obfuscation</title>
<style>
.something-else {
font-size: 15pt;
}
</style>
<script>
// Extreme E-Mail Obfuscation
// Christopher Harrison (MIT License) 2012
// The actual e-mail address is XOR encrypted in the source and
// decrypted on-the-fly. (An improvement may be creating an AJAX
// service that returns an encrypted address and key dynamically,
// rather than having it hard-coded.)
// No e-mail links exist in the source; they are generated through
// DOM manipulation upon page load, by searching for elements with
// a particular class ('xMail'). This, therefore, requires
// getElementsByClassName support; but that can be retrofitted
// manually, if necessary.
function decryptEMail() {
var key = 'Harvest this!';
var xMail = [32, 8, 0, 19, 37, 11, 27, 80, 28, 70, 10, 28];
var plain = '';
for (var i in xMail) {
plain += String.fromCharCode(key.charCodeAt(i % key.length) ^ xMail[i]);
}
return plain;
}
function buildMailers() {
if (document.getElementsByClassName) {
var mailers = document.getElementsByClassName('xMail');
var addrURL = 'mailto:' + decryptEMail();
for (var i = mailers.length - 1; i >= 0; i--) {
var mailer = mailers[i];
var cloneMail = mailer.cloneNode(true);
cloneMail.className = cloneMail.className.replace(/(?:^|\s)xMail(?!\S)/, '');
var newLink = document.createElement('a');
newLink.setAttribute('href', addrURL);
newLink.appendChild(cloneMail);
with(mailer.parentNode) {
insertBefore(newLink, mailer);
removeChild(mailer);
}
}
}
}
</script>
</head>
<body onload="buildMailers();">
<div><img class="xMail" src="http://xoph.co/wp-content/uploads/2012/06/hire.png" /></div>
<div><span class="xMail">Employ</span> <span class="xMail">me</span> <span class="xMail">now!</span></div>
<div><p>Here is an <em class="xMail something-else">obfuscated e-mail link</em>.</p></div>
</body>
</html>
@Xophmeister
Copy link
Author

I should note that supplying the cipher-text, key and decryption algorithm doesn't make the data "encrypted"! However, the point is to make it very difficult for scrapers: I guess a generalised spam bot that could extract the data from this would need to implement a JavaScript VM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment