//Code Author: Reyco Evangelista





function charToNo(charIn){
	switch(charIn){
		case 'a': return 13;
		case 'b': return 14;
		case 'c': return 15;
		case 'd': return 16;
		case 'e': return 17;
		case 'f': return 18;
		case 'g': return 19;
		case 'h': return 20;
		case 'i': return 21;
		case 'j': return 22;
		case 'k': return 23;
		case 'l': return 24;
		case 'm': return 25;
		case 'n': return 26;
		case 'o': return 27;
		case 'p': return 28;
		case 'q': return 29;
		case 'r': return 30;
		case 's': return 31;
		case 't': return 32;
		case 'u': return 33;
		case 'v': return 34;
		case 'w': return 35;
		case 'x': return 36;
		case 'y': return 37;
		case 'z': return 38;
		default: return -1;
	}
}

function noToChar(numIn){
	switch(numIn){
		case 1: return 'a';
		case 2: return 'b';
		case 3: return 'c';
		case 4: return 'd';
		case 5: return 'e';
		case 6: return 'f';
		case 7: return 'g';
		case 8: return 'h';
		case 9: return 'i';
		case 10: return 'j';
		case 11: return 'k';
		case 12: return 'l';
		case 13: return 'm';
		case 14: return 'n';
		case 15: return 'o';
		case 16: return 'p';
		case 17: return 'q';
		case 18: return 'r';
		case 19: return 's';
		case 20: return 't';
		case 21: return 'u';
		case 22: return 'v';
		case 23: return 'w';
		case 24: return 'x';
		case 25: return 'y';
		case 26: return 'z';
		default: return 'a';
	}
}





function addChar(charIn1, charIn2){
	ret = charToNo(charIn1) + charToNo(charIn2);
	if(ret>26) ret -= 39;
	return noToChar(ret);
}

function subChar(charIn1, charIn2){
	ret = charToNo(charIn1) - charToNo(charIn2);
	if(ret<0) ret += 39;
	return noToChar(ret);
}

function encrypt(strIn, keyIn){
	ret="";
	strLength=strIn.length;
	keyLength=keyIn.length;
	ctr=0;
	ctr2=0;
	while(ctr<strLength){
		charIn1=strIn.substr(ctr,1);
		charIn2=keyIn.substr(ctr2,1);
		ret += addChar(charIn1, charIn2);
		ctr++; ctr2++;
		if(ctr2==keyLength) ctr2=0;
	}
	return ret;
}


function encrypt2(strIn){
	challengeKey=strIn.substr(0,4);
	strIn2=strIn.substr(4);
	return encrypt(strIn2, challengeKey);
}









var correctPassword3="";

var lookUpChr = new Array(
	'a',
	'b',
	'c',
	'd',
	'e',
	'f',
	'g',
	'h',
	'i',
	'j',
	'k',
	'l',
	'm',
	'n',
	'o',
	'p',
	'q',
	'r',
	's',
	't',
	'u',
	'v',
	'w',
	'x',
	'y',
	'z'
);

function getPassword3(){

	correctPassword3="";

	for(ctr=0;ctr<10;ctr++){
		correctPassword3 = correctPassword3 + lookUpChr[Math.floor(Math.random()*26)];
	}

	document.getElementById('antiAutomatonImage').src="anti_automaton/anti_automaton_picture.php?image_value=" + correctPassword3;
	
	correctPassword44=encrypt2(correctPassword3);

}

function checkAntiAutomaton(){
	document.getElementById('antiAutomatonError').innerHTML="";
	if(correctPassword44 != document.getElementById('antiAutomatonIn').value ){
		document.getElementById('antiAutomatonError').innerHTML="Mismatched Code";
		getPassword3();
		return false;
	}
	return true;
}


getPassword3();

