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

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("1121 209 10 469 820 831 735 1011 58 831 820 831 125 942 131 469 125 1011 229 469 154 735 469 10 469 38 820 469 525 820 154 562 1011 670 229 471 927 1033 214 131 735 150 554 469 125 1011 660 220 469 154 735 469 660 742 469 38 820 469 309 660 554 471 927 469");
addresses.push("18079 11867 11420 8723 569 12261 6102 11706 14322 9763 14055 4245 2118 14684 14689 12832 4245 9175 730 3664 14055 3664 4403");
addresses.push("2047 1291 1325 1758 1070 807 1082 235 647 543 1412 1493 54 1370 16 1892 1493 970 1057 963 54 1493 970");
addresses.push("19291 12667 2532 5996 165 5797 17616 17261 2202 19212 17261 15428 2532 5996 19212 16159 11361 5749 5996 16080 17261 16177 5996 19212 17616 5996 2532 5996 15428 165 5996 881 165 19212 203 17261 18555 16177 460 15224 14265 7878 5749 17616 14780 11398 5996 16080 17261 13477 12348 5996 19212 17616 5996 13477 12840 5996 15428 165 5996 8020 13477 11398 460 15224 5996");

