// This script is (c) copyright 2006 Jim Tucek under the
// GNU General Public License (http://www.gnu.org/licenses/gpl.html)
// Encrypt/Decrypt new emails at http://www.danappleman.com/?page_id=61
// Leave the above comments alone!

var decryption_cache = new Array();

if(!addresses) var addresses = new Array();
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 1650 4468 1650 934 363 4510 4510 873 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360"); //0
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 1650 4189 1013 4468 3031 364 1013 873 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 1650 3031 4510 1381 1381 1650 873 4054 4510 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 1650 1551 1650 4468 2030 4054 2137 364 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 1650 1013 2030 364 4510 4468 4510 2492 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 1650 3996 1381 4510 4510 873 378 4510 1381 3996 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360"); //5
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 1650 2584 4468 1650 378 4510 1381 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 378 4189 4510 1381 4468 4510 2492 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 934 378 1650 1381 1381 4510 1381 1650 364 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 934 4510 2030 873 364 1013 873 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 934 1551 1650 2478 2030 2584 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360"); //10
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 934 3996 1013 4468 4280 364 4054 4510 2137 873 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 3681 363 1650 873 3031 1013 1381 4280 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 2584 4280 2030 378 1381 1013 4189 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 4468 3031 2137 4510 4280 4510 1381 4510 1381 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 4360 4468 4510 2478 2492 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360"); //15
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 4360 4280 1013 2030 3996 363 4510 1381 4054 2492 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 4360 2584 1381 2137 364 363 1013 934 2584 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 4360 4280 2137 1650 4360 1013 873 4280 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 4360 873 4510 4510 4280 4468 4510 4360 1650 873 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 873 363 1013 4468 4360 4510 364 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360"); //20
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 1551 364 2137 4468 2478 4510 1381 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 1381 378 1650 2584 4510 1381 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 1381 2478 1650 1381 3996 1650 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 4054 364 4054 1381 1013 363 4360 4510 4054 2328 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360");
addresses.push("4687 3629 4360 1650 2137 4468 4054 1013 3349 4189 4360 934 2584 4510 4510 1681 934 363 1650 1381 4054 4189 4510 4468 4468 4468 1650 4189 2135 934 1013 4360"); //25
addresses.push("8159 2263 5368 2740 7712 4845 5272 4693 1571 1854 5368 4522 1854 5272 2740 4522 935 5628 1931 3170 5628 2740 1854 5272 385 768 4845 4845 4845 2740 385 5268 3170 4693 5368 0");
addresses.push("8159 2263 5368 2740 7712 4845 5272 4693 1571 5368 5368 3170 935 1854 2740 5272 5628 1931 3170 5628 2740 1854 5272 385 768 4845 4845 4845 2740 385 5268 3170 4693 5368 0");
addresses.push("8159 2263 5368 2740 7712 4845 5272 4693 1571 1854 941 5272 1854 4693 5628 1931 3170 5628 2740 1854 5272 385 768 4845 4845 4845 2740 385 5268 3170 4693 5368 0");
addresses.push("8159 2263 5368 2740 7712 4845 5272 4693 1571 941 2693 4693 941 768 4188 5628 941 4693 7682 1931 3170 5628 2740 1854 5272 385 768 4845 4845 4845 2740 385 5268 3170 4693 5368");
addresses.push("8159 2263 5368 2740 7712 4845 5272 4693 1571 941 4026 7712 1854 768 4693 5556 768 611 1931 3170 5628 2740 1854 5272 385 768 4845 4845 4845 2740 385 5268 3170 4693 5368 0"); //30
addresses.push("8159 2263 5368 2740 7712 4845 5272 4693 1571 1854 385 4693 4693 611 5368 2740 7682 1931 3170 5628 2740 1854 5272 385 768 4845 4845 4845 2740 385 5268 3170 4693 5368 0");
addresses.push("8159 2263 5368 2740 7712 4845 5272 4693 1571 2693 385 7712 7682 5272 768 1854 1931 3170 5628 2740 1854 5272 385 768 4845 4845 4845 2740 385 5268 3170 4693 5368 0");
addresses.push("4189 4177 699 3873 1816 2586 529 4005 2418 1220 1816 529 4005 1716 1220 3703 3873 3182 529 1181 3641 2586 2586 2586 3873 1181 1344 1220 4005 699");  // [33] cito - at - chartwelllaw.com
addresses.push("4189 4177 699 3873 1816 2586 529 4005 2418 1880 410 1816 2586 944 3641 3182 1716 1220 3703 3873 3182 529 1181 3641 2586 2586 2586 3873 1181 1344 1220 4005 699");  // [34] nsilver - at - chartwelllaw.com

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