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("10229 1997 2787 2696 264 7611 6296 2065 2754 7611 264 7611 5026 3694 6852 7581 2763 6296 264 7611 264 10034 2065 2061 9428 2065 2787 8734 2763 10001 4332 2862 7581 9428 6296 8229 9196 264 4332 2696 9428 2065 2696 4286 3312 9626 10001 4332 2696");
addresses.push("2173 1387 2094 13 1589 1545 682 814 1715 983 1536 1113 1942 1558 173 1008 1113 307 2032 1227 1536 1227 488");
addresses.push("7597 4947 3539 1033 2881 6207 3511 171 5187 3224 3862 4534 4234 548 2380 5524 4534 3694 7558 2865 4234 4534 3694");
addresses.push("31897 21027 19149 19557 9333 15729 29840 27957 3730 23223 27957 14282 19149 19557 23223 11193 6968 11193 9597 21716 29840 9333 15729 9333 23223 27957 1645 13389 27957 19149 26768 21716 6763 16179 10827 9597 13389 29840 3702 22460 9333 16179 19557 13389 27957 19557 21390 871 13690 6763 16179 19557");
addresses.push("395 125 74 362 250 63 206 51 278 25 51 384 74 362 25 275 289 275 146 50 206 250 63 250 25 51 101 184 51 74 228 50 222 318 216 146 184 206 191 114 250 318 362 184 51 362 169 367 97 222 318 362 367 200 384 146 57 362 50 367 275 146 367 63 362 25 293 51 222 50 206 146 331");

