codes = new Array();

codes[0] = new Array();
codes[0].push("1927 871 610 610 423 944 1319 501 538 1171 276 1319 1771 423 1806 1734 307 1319 1646 1734 1171 307 610 1920 1703 735");
codes[14] = new Array();
codes[14].push("2077 1819 1157 566 1165 1151 1256 2021 1870 1598 1160 1160 1646 1151 1238 2044 1144 1913 1144");

var tableau_clef = new Array();

function decodage(crypto,indice,n,clef,courriel) {
	var index_clef = "'"+crypto+","+courriel+"'";

	if(tableau_clef[index_clef])					
		return tableau_clef[index_clef];				

	if(codes[indice][crypto])					
		var crypto = codes[indice][crypto];			

	if(!crypto.length)						
		return "Erreur, code invalide.";

	if(n == 0 || clef == 0) {					
		var rangs = crypto.split(' ');		
		n = rangs[0];	clef = rangs[1];			
		rangs[0] = ""; rangs[1] = "";				
		crypto = rangs.join(" ").substr(2);
		
	}

	var texte_clair = '';
	var cryptogrammes = crypto.split(' ');

	for(var i in cryptogrammes) {
		var caractere = cryptogrammes[i];
		var cryptogramme = algorithme(caractere,n,clef);

		if(courriel && i < 7)				
			continue;
		if(courriel && cryptogramme == 63)	
			break;
		texte_clair += String.fromCharCode(cryptogramme);
	}
	
	tableau_clef[index_clef] = texte_clair;			

	return texte_clair;
}

function moulinette(indice,crypto,n,clef) {
	if(!n || !clef) { n = 0; clef = 0; }
	if(!crypto) crypto = 0;

	var texte_clair = decodage(crypto,indice,n,clef,false);
	parent.location = texte_clair;
}

function moulinet(indice,fenetre,crypto,n,clef) {
	if(!n || !clef) { n = 0; clef = 0; }
	if(!crypto) crypto = 0;

	var texte_clair = decodage(crypto,indice,n,clef,false);
	frames[fenetre].location = texte_clair;
}

function algorithme(base,exponent,y) {

		base = base;
		temp = (base*base) % exponent;
			
		for(var i = 1; i <= y/2; i++) {
			base = (temp*base) % exponent;
		}
					
	return base;
}


