// This script was written by Jason Barnette on June 28, 2004
// Anyone is free to use this script or modify as you see fit

// This script decrypts all encrypted email address in a website
function decrypt(address, keyOne, keyTwo) {

	// Variables
	var howLong = address.length + 1;
	var counter = 0;
	var finalAddress = "";

	// Adds a space to the end of the address code
	address += " ";
	
	// Loop that works on translating the code
	for (var count=0; count < howLong; count++) {
		counter = 0;
		
		// Loop that handles one piece of code at a time
		while (address.charCodeAt(count) != 32) {
			counter = counter * 10;
			counter = counter + address.charCodeAt(count) - 48;
			count++;
		}
		
		// Calls the translation function to convert the coded character
		finalAddress += String.fromCharCode(translate(counter,keyOne,keyTwo));
	}
	
	// Returns the final translated address
	parent.location = "m" + "a" + "i" + "l" + "t" + "o" + ":" + finalAddress;
}

function translate(counter, keyOne, keyTwo) {
	// Variables
	counterAgain = counter;

	// Loop that works until code is translated
	for (var num = 1; num <= keyTwo/2; num++) {
		numAgain = (counter * counter) % keyOne;
		counterAgain = (numAgain * counterAgain) % keyOne;
	}
	
	// Returns the value to the first function
	return counterAgain;
}

