/* EMAIL ENCRYPTION SCRIPT */

// This script is (c) copyright 2008 by Dan Appleman under the
// GNU General Public License (http://www.gnu.org/licenses/gpl.html)
// This script is modified from an original script by Jim Tucek
// For more information, visit www.danappleman.com 
// Leave the above comments alone!
// see encryption_instructions.txt for explanation of usage

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;
}

// Remove the comments below to improve spam resistance! 
// email addresses: 

 if(!addresses) var addresses = new Array();
addresses.push("17111 17107 16758 3946 1585 7787 5000 2213 5760 3946 13656 16758 1585 16310 12468 807 17085 17085 7787 558 3946 15821 17085 5000 14974 1061 1585 7787 7787 3946 10812 17085 14976 2213 16310 14976 5289 3946 13474 558 12846 3702 9393 17085 5289 5000 6707 16950 11500 12958 1585 558 5000 1585 17085 5589 558 1085 8526 17085 3702 558 1585 5000 17085 1085 11901 16758 3946 1585 7787");  // [0] admin - at - peelsafetyvillage.on.ca

// Remove the comments below to improve spam resistance! 
// email addresses: 

 if(!addresses) var addresses = new Array();
addresses.push("4579 4567 3195 90 262 1853 2712 3057 4314 90 1365 3195 262 4269 900 2095 3638 3638 1853 1008 90 3959 3638 2712 691 2989 262 1853 1853 90 1148 3638 730 3057 4269 730 3483 90 1890 1008 2985 2738 3127 3638 3483 2712 2210 20 262 3483 1942 3638 1853 1853 3638 1635 1008 3012 1778 3638 2738 1008 262 2712 3638 3012 2273 3195 90 262 1853");  // [1] admin - at - peelsafetyvillage.on.ca

// Remove the comments below to improve spam resistance! 
// email addresses: 

 
if(!addresses) var addresses = new Array();
addresses.push("6119 6113 64 3826 1808 4295 2784 3293 2465 3826 294 64 1808 2920 1459 5099 456 456 4295 1623 3826 1835 456 2784 5233 5782 1808 4295 4295 3826 5622 456 2714 3293 2920 2714 5029 3826 3464 1623 813 1063 1568 456 5029 2784 710 839 3826 2920 2920 5233 317 1623 2160 957 456 1063 1623 1808 2784 456 2160 5790 64 3826 1808 4295");  // [2] admin - at - peelsafetyvillage.on.ca


// Remove the comments below to improve spam resistance! 
// email addresses: 

if(!addresses) var addresses = new Array();
addresses.push("13439 13421 3758 8641 2152 3452 9407 1802 7062 8641 1257 3758 2152 1356 64 11458 9333 9333 3452 10565 8641 2479 9333 9407 8487 8337 2152 3452 3452 8641 4970 9333 12948 1802 1356 12948 9889 8641 1183 10565 12699 9443 4289 9333 9889 9407 7148 11137 8641 2428 13190 2887 10565 12047 87 9333 9443 10565 2152 9407 9333 12047 11372 3758 8641 2152 3452");  // [3] admin - at - peelsafetyvillage.on.ca

