/* 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("46031 46027 39395 1295 17936 7787 45247 21646 14436 7484 21646 28516 45247 1295 7484 45247 43557 21646 45247 9800 39395 20535 7484 4846 27289 45247 17936 37922 17936 7484 1295 27289 4846 14185 27289 21646");  // [0] contact - at - otdm-certificare.ro
addresses.push("46031 46027 39395 1295 17936 7787 45247 21646 14436 21646 1295 28516 1295 14185 1295 27289 18963 4846 28516 4846 18963 7484 28365 43557 21646 45247 9800 39395 20535 7484 4846 27289 45247 17936 37922 17936 7484 1295 27289 4846 14185 27289 21646");  // [1] oana.arsenescu - at - otdm-certificare.ro
addresses.push("46031 46027 39395 1295 17936 7787 45247 21646 14436 6122 17936 27289 21482 17936 28516 17936 1295 14185 9800 17936 28516 28365 43557 21646 45247 9800 39395 20535 7484 4846 27289 45247 17936 37922 17936 7484 1295 27289 4846 14185 27289 21646");  // [2] virginia.dinu - at - otdm-certificare.ro
addresses.push("46031 46027 39395 1295 17936 7787 45247 21646 14436 7484 27289 17936 18963 45247 17936 28516 1295 14185 9800 28365 27289 7787 4846 43557 21646 45247 9800 39395 20535 7484 4846 27289 45247 17936 37922 17936 7484 1295 27289 4846 14185 27289 21646");  // [3] cristina.durle - at - otdm-certificare.ro
addresses.push("46031 46027 39395 1295 17936 7787 45247 21646 14436 7484 36941 27289 17936 18963 45247 17936 1295 28516 14185 36941 4846 17936 28516 27289 17936 7484 36941 43557 21646 45247 9800 39395 20535 7484 4846 27289 45247 17936 37922 17936 7484 1295 27289 4846 14185 27289 21646");  // [4] christian.heinrich - at - otdm-certificare.ro
addresses.push("46031 46027 39395 1295 17936 7787 45247 21646 14436 39395 1295 27289 17936 7787 4846 28516 1295 14185 21124 27289 17936 810 21646 17936 1295 28516 28365 43557 21646 45247 9800 39395 20535 7484 4846 27289 45247 17936 37922 17936 7484 1295 27289 4846 14185 27289 21646");  // [5] marilena.priboianu - at - otdm-certificare.ro
addresses.push("46031 46027 39395 1295 17936 7787 45247 21646 14436 17936 21646 1295 28516 1295 14185 45247 4846 28516 4846 43557 21646 45247 9800 39395 20535 7484 4846 27289 45247 17936 37922 17936 7484 1295 27289 4846 14185 27289 21646");  // [6] ioana.tene - at - otdm-certificare.ro
addresses.push("46031 46027 39395 1295 17936 7787 45247 21646 14436 21482 4846 21646 27289 21482 4846 45247 1295 14185 36941 4846 27289 45247 1295 43557 21646 45247 9800 39395 20535 7484 4846 27289 45247 17936 37922 17936 7484 1295 27289 4846 14185 27289 21646");  // [7] georgeta.herta - at - otdm-certificare.ro
addresses.push("27161 27143 11739 17775 8638 12733 4216 20311 26173 11739 17775 21896 8638 20734 17775 7164 19472 20311 8638 7111 4604 10232 17775 20734 11739 7164 21896 20311");  // [8] marina.voicu - at - anm.ro
addresses.push("27161 27143 11739 17775 8638 12733 4216 20311 26173 17775 4604 21896 956 12733 8638 17775 20734 7164 11923 17775 11739 18349 8638 21896 10232 17775 20734 11739 7164 21896 20311");  // [9] aurelian.zamfir - at - anm.ro
addresses.push("27161 27143 11739 17775 8638 12733 4216 20311 26173 7111 17775 21896 11739 956 20734 7164 6351 4216 17775 11739 7371 956 12733 4604 10232 17775 20734 11739 7164 21896 20311");  // [10] carmen.stambelu - at - anm.ro
addresses.push("27161 27143 11739 17775 8638 12733 4216 20311 26173 11739 8638 21896 20311 20734 7164 17775 20734 4216 20311 20734 956 17775 20734 4604 10232 17775 20734 11739 7164 21896 20311");  // [11] miron.antoneanu - at - anm.ro
addresses.push("27161 27143 11739 17775 8638 12733 4216 20311 26173 6351 20311 21896 8638 20734 7164 21896 20311 6351 7111 17775 10232 17775 20734 11739 7164 21896 20311");  // [12] sorin.rosca - at - anm.ro
addresses.push("27161 27143 11739 17775 8638 12733 4216 20311 26173 11739 17775 21896 8638 17775 7164 20734 8638 7111 4604 12733 17775 956 10232 17775 20734 11739 7164 21896 20311");  // [13] maria.niculae - at - anm.ro

