Email Address Scrambler

When you put your email address in your web page you publish it to the entire world. That is both a good thing and a bad thing. It’s good because lots of potential customers can contact you and do business with you. It’s bad because some very annoying people called spammers can get your email address and send you lots of advertising for products you don’t want. Spammers use programs called spam-bots to generate their email lists. Spam-bots automatically search the web downloading all the web pages they can find and searching them for email addresses. One way to fool the spam-bots is to scramble the email addresses in your web page and have the page reference a decoder script that is run on the user’s browser.

This works most of the time because most spam-bots only download the HTML source of your web page and don’t download and run any scripts associated with the page. They just search the raw HTML for anything that looks like an email address. If your HTML file has all the email addresses scrambled, the spam-bots may not even recognize them as email addresses, and if they do, they almost certainly won’t be able to decode them.

Here is an email scrambler with a script you can include in your web page to decode scrambled email addresses. Type an email address in the input field below then click the “Scramble” button.

email address:

Insert this anchor element in your html document...

...and it will create this email link after decoding:

Here is the JavaScript for decoding a scrambled email address:


function merge ( indices1, indices2, text ) 

{
   var result = new Array ()

   var length1 = indices1.length
   var ix1 = 0
   var length2 = indices2.length
   var ix2 = 0
   var length = 0

   while ( ix1 < length1 && ix2 < length2 ) {

	if ( text.charCodeAt ( indices1 [ix1] )
					> text.charCodeAt ( indices2 [ix2] ) )
		result [length++] = indices2 [ix2++]
	else result [length++] = indices1 [ix1++]
   }

   while ( ix1 < length1 ) result [length++] = indices1 [ix1++]

   while ( ix2 < length2 ) result [length++] = indices2 [ix2++]

   return ( result )
}


function mergeSort ( indices, text, start, length )

{
   var result

   if ( length > 1 ) {

	var length2 = ( length - ( length % 2 ) ) / 2
	var result1 = mergeSort ( indices, text, start, length2 )
	var result2 = mergeSort ( indices, text, start + length2,
							length - length2 )

	result = merge ( result1, result2, text )

   } else {

	result = new Array()

	result [0] = indices [start]
   }

   return ( result )
}


function bwtDecode ( cypher )

{
   var code = ""
   var plainText = ""
   var length = cypher.length
   var indices = new Array ()
   var key = 0
   var i = 0
   var j = 0

   while ( i < length ) {

	var ch = cypher.charAt ( i )

	if ( ch != " " && ch != "\t" && ch != "\n" && ch != "\r" ) {

		indices [j] = j
		code += ch
		++j

	} else if ( ! key ) key = j

	++i
   }

   length = j

   if ( key == length ) key = 0

   if ( length > 0 ) {

	indices = mergeSort ( indices, code, 0, length )

	j = key

	while ( length-- > 0 ) {

		var ch

		j = indices [j]

		ch = code.charAt ( j )

		if ( ch == "\\" && length-- > 0 ) {

			j = indices [j]

			ch = code.charAt ( j )

			switch ( ch ) {

			  case "r":

				ch = "\r"
				break

			  case "n":

				ch = "\n"
				break

			  case "s":

				ch = " "
				break

			  case "t":

				ch = "\t"
				break

			  case "x":

				var digits = length
				var chCode = 0

				if ( digits > 2 ) digits = 2

				while ( digits-- > 0 ) {

					var littleA = "a".charCodeAt (0)
					var bigA = "A".charCodeAt (0)

					--length
					j = indices [j]
					ch = code.charCodeAt ( j )

					if ( ch > littleA ) ch
							-= ( littleA - 10 )
					else if ( ch > bigA ) ch
							-= ( bigA - 10 )
					else ch -= "0".charCodeAt (0)

					chCode *= 16
					chCode += ch
				}

				ch = String.fromCharCode ( chCode )

				break;
			}
		}

		plainText += ch
	}
   }

   return ( plainText )
}


function decodeEntities ( htmlText )

{
   var text = ""
   var length = htmlText.length
   var i = 0

   while ( i < length ) {

	var ch = htmlText.charAt ( i++ )

	if ( ch == "&" ) {

		var remainder = length - i

		if ( remainder > 3
			&& htmlText.substring ( i, i + 4 ) == "amp;" ) i += 4

		else if ( remainder > 2 ) {

			switch ( htmlText.substring ( i, i + 3 ) ) {

			  case "gt;":

				ch = ">"
				i += 3
				break

			  case "lt;":

				ch = "<"
				i += 3
				break
			}
		}
	}

	text += ch
   }

   return ( text )
}


function useHTMLentities ( text )

{
   var htmlText = ""
   var length = text.length
   var i = 0

   while ( i < length ) {

	var ch = text.charAt ( i++ )

	switch ( ch ) {

	  case "&":

		htmlText += "&amp;"
		break

	  case "<":

		htmlText += "&lt;"
		break

	  case ">":

		htmlText += "&gt;"
		break

	  default:

		htmlText += ch
		break
	}
   }

   return ( htmlText )
}


function decodeEmail ()

{
   var addresses = document.getElementsByName ( "e_mail" )
   var length = addresses.length
   var i

   for ( i = 0; i < length; i++ ) {

	if ( addresses [i].href == "mailto:" ) {

		var address
		= bwtDecode ( decodeEntities ( addresses [i].innerHTML ) )

		addresses [i].href += address
		addresses [i].innerHTML = useHTMLentities ( address )
	}
   }
}
            

Cut and paste the JavaScript above into a file named “decodeEmail.js” located in the same directory as your HTML file. An HTML file that includes a scrambled link to the email address:

Will have the following elements at a minimum:

<html>
<head>
<title>My Page</title>
<script type="text/javascript" src="decodeEmail.js"></script>
</head>
<body onload="decodeEmail()">
<a href="mailto:" name="e_mail">eela.cnmmpoooosscee m@</a>
</body>
</html>

Try cutting and pasting the example HTML file above into a file named “example.html”. Be sure you have created the “decodeEmail.js” file and the two files are in the same directory. Now try displaying the “example.html” file with your web browser. You should see the decoded email address (someone@someplace.com). If so, congratulations, you have gotten the script working. Now use the scrambler at the top of this page to generate anchor elements for all the email addresses you want in your web page, and put them into your new HTML file. This should get you started hiding your email addresses from spam-bots. Good luck!