// This script is (c) copyright 2006 Jim Tucek under the
// GNU General Public License (http://www.gnu.org/licenses/gpl.html)
// For more information, visit www.jracademy.com/~jtucek/email/ 
// Leave the above comments alone!

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;
}

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;
}

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;
}

// 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;
}
// -->

var addresses = new Array();
addresses.push("432 193 6984 10624 162 1581 9538 1581 9921 9921 6984 1195 5996 3235 193 6899 6453 162 9863 193 5561 5996 193 4945 1195 1581 432");
addresses.push("19075 8408 15980 15477 9613 9842 13050 15333 19370 5932 8408 15333 6032 9613 13116 8408 6432 11813 8408 15433 2678 9842 19075");
addresses.push("6947 283 3805 2433 5578 2579 5887 4402 4402 2659 283 5440 4237 5578 2252 283 3896 7019 283 3893 1922 2579 6947");
addresses.push("1403 636 830 1387 866 567 1441 100 1076 97 636 73 1447 866 1408 636 1066 808 636 798 998 567 1403");
addresses.push("628 3660 1461 3012 2588 2017 2418 2856 2827 2426 3660 2827 268 2588 2212 3660 3087 3996 3660 989 2640 2017 628");
addresses.push("10363 11153 8187 8853 5774 4082 3539 4082 1922 1922 8187 1165 4822 2957 11153 5305 10829 5774 9233 11153 1258 4822 11153 7184 1165 4082 10363 2129 10829 1415 5865 7771 4822 1165 5774 1601 10456 4822 10829 1415 10363 4822 10230 5305 4822 465 1415 4822 10829 5774");
addresses.push("432 193 6984 10624 162 1581 9538 10095 193 1195 5996 7016 3235 193 6899 6453 162 9863 193 5561 5996 193 4945 1195 1581 432");

var _c = [
		  [0,10721,8591] ,
		  [1,21473,12701] ,
		  [2,7031,1373] ,
		  [3,1457,1183] ,
		  [4,4189,2707],
		  [6,10721,8591]

		  ];
var _d = decrypt_and_email;

