/* EMAIL ENCRYPTION SCRIPT */

// This script is (c) copyright 2008 by Dan Appleman under the
// GNU General Public License (http://www.gnu.org/licenses/gpl.html)
// This script is modified from an original script by Jim Tucek
// For more information, visit www.danappleman.com 
// Leave the above comments alone!
// see encryption_instructions.txt for explanation of usage

var decryption_cache = new Array();

function decrypt_string(crypted_string,n,decryption_key,just_email_address) {
	var cache_index = "'"+crypted_string+","+just_email_address+"'";

	if(decryption_cache[cache_index])					// If this string has already been decrypted, just
		return decryption_cache[cache_index];				// return the cached version.

	if(addresses[crypted_string])						// Is crypted_string an index into the addresses array
		var crypted_string = addresses[crypted_string];			// or an actual string of numbers?

	if(!crypted_string.length)						// Make sure the string is actually a string
		return "Error, not a valid index.";

	if(n == 0 || decryption_key == 0) {					// If the decryption key and n are not passed to the
		var numbers = crypted_string.split(' ');			// function, assume they are stored as the first two
		n = numbers[0];	decryption_key = numbers[1];			// numbers in crypted string.
		numbers[0] = ""; numbers[1] = "";				// Remove them from the crypted string and continue
		crypted_string = numbers.join(" ").substr(2);
	}

	var decrypted_string = '';
	var crypted_characters = crypted_string.split(' ');

	for(var i in crypted_characters) {
		var current_character = crypted_characters[i];
		var decrypted_character = exponentialModulo(current_character,n,decryption_key);
		if(just_email_address && i < 7)				// Skip 'mailto:' part
			continue;
		if(just_email_address && decrypted_character == 63)	// Stop at '?subject=....'
			break;
		decrypted_string += String.fromCharCode(decrypted_character);
	}
		decryption_cache[cache_index] = decrypted_string;			// Cache this string for any future calls

	return decrypted_string;
}

// Finds base^exponent % y for large values of (base^exponent)
function exponentialModulo(base,exponent,y) {
	if (y % 2 == 0) {
		answer = 1;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	} else {
		answer = base;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	}
	return answer;
}

// return string to open an email compose window with:
//  mailto:<email address> or
//  mailto:<email address>?subject=<subject>
function decrypt_and_email(crypted_string,n,decryption_key) {
	if(!n || !decryption_key) { n = 0; decryption_key = 0; }
	if(!crypted_string) crypted_string = 0;

	var decrypted_string = decrypt_string(crypted_string,n,decryption_key,false);
	parent.location = decrypted_string;
}

// return string of the form:
//  mailto:<email address> or
//  mailto:<email address>?subject=<subject>
function decrypt_and_echo(crypted_string,n,decryption_key) {
	if(!n || !decryption_key) { n = 0; decryption_key = 0; }
	if(!crypted_string) crypted_string = 0;

	var decrypted_string = decrypt_string(crypted_string,n,decryption_key,true);
	document.write(decrypted_string);
	return true;
}

// return string of the form: <email address> from input of the form:
//  mailto:<email address> or
//  mailto:<email address>?subject=<subject>
function decrypt_and_fillform_eaddr(element,crypted_string,n,decryption_key) {
	if(!n || !decryption_key) { n = 0; decryption_key = 0; }
	if(!crypted_string) crypted_string = 0;

	var decrypted_string = decrypt_string(crypted_string,n,decryption_key,true);
	// strip off non-email address elements
	if( decrypted_string.indexOf("?") > 0) {
		element.value=decrypted_string.substring(decrypted_string.indexOf(":")+1, decrypted_string.indexOf("?"));
	} else {
		element.value=decrypted_string.substring(decrypted_string.indexOf(":")+1);
	}
	return true;
}

<!-- This script block stores your encrypted email address(es) in --> 
<!-- the addresses array.  If you ever want to add new addresses to --> 
<!-- a page, you can return to http://www.danappleman.com/ --> 
<!-- and generate more, and then add this block to your existing page. --> 
<!-- Remove the comments to improve spam resistance! --> 

if(!addresses) var addresses = new Array();
addresses.push("5029 5023 1915 1839 1188 1285 278 2368 3068 1188 4379 397 2368 2744 3899 1078 1839 1915 994 1188 2368 4379 2414 982 4379 4266 1188 4379 982 982 2275 1188 4379 4266 1456 3899 2368 1915 2969 2414 2976 578 2246 982 3899 278 4857 66 1078 1839 1915 994 1188 2368 4379 2414 1375 1876 4379 4266 1188 4379 982 982 2275 1188 4379 4266 3068 1375 3273 4379 397 2368 2275 1915 1839 278 1188 2368 4379 1375 2275 982 4582 2976 982 2414 278");  // [0] info - at - championsengineering.com; Subject=Champions Engineering: Information request
addresses.push("3379 3373 1744 2837 365 1852 2478 1652 1255 641 2297 2487 2487 1652 135 2478 500 2610 1718 2837 1744 2487 365 1652 2399 641 2172 2399 1539 365 2399 2172 2172 135 365 2399 1539 1790 2610 1652 1744 63 641 2297 563 456 2172 2610 2478 867 1803 1718 2837 1744 2487 365 1652 2399 641 1985 555 2399 1539 365 2399 2172 2172 135 365 2399 1539 1255 1985 79 1671 1744 365 2399 365 641 2478 135 2837 2478 365 3125 2172 1985 2033 2297 2172 641 2478 365 1652 2399");  // [1] support - at - championsengineering.com; subject=Champions Engineering: Administrative question
