// 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;
}
if(!addresses) var addresses = new Array();
addresses.push("1343 749 232 836 566 1248 522 841 436 218 1248 836 595 700 67 1131 658 67 16 1237 761 658 593 841 841 1248 761 496 1131 1137 658 496 1004 841 985 0 1176 761 1328 81 769 67 658 522 1060 492 841 1131 522 836 658 522");
addresses.push("1343 749 232 836 566 1248 522 841 436 232 218 841 1248 522 1328 985 1237 836 1137 836 496 1137 836 1248 67 496 67 512 1328 0 1176 761 1328 81 769 67 658 522 1060 492 841 1131 522 836 658 522");
addresses.push("1343 749 232 836 566 1248 522 841 436 700 232 1328 566 700 1237 595 836 522 658 593 593 67 836 1248 522 593 496 841 700 1004 0 1176 761 1328 81 769 67 658 522 1060 492 841 1131 522 836 658 522");
addresses.push("1343 749 232 836 566 1248 522 841 436 1004 67 1131 566 1131 1003 841 1237 81 232 761 1003 593 658 496 841 700 1004 1176 761 1328 81 769 67 658 522 1060 492 841 1131 522 836 658 522");
addresses.push("2561 941 2527 2498 417 1687 2521 583 639 1049 2498 2331 2357 522 2521 2331 2357 1687 1687 2498 1598 664 2357 2331 417 941 583 522 2234 522 2357 2521 384 319 91 2247 1254 2357 905 2521 1550 905 583 522 2521 2498 905 2521 392 1049 2498 2331 2357 522 1598 664 417 2331 417 941 583 522 2234 522 2357 2521");
// -->
