codes = new Array();

codes[0] = new Array();
codes[0].push("1961 1099 897 897 195 1338 999 78 78 635 1174 1631 195 635 1627 248 1174 268 897 622 365 853");
codes[1] = new Array();
codes[1].push("2483 1397 1922 1922 372 473 355 56 2315 2406 307 355 1385 372 1995 158 2040 355 2246 158 2406 2040 1922 2002 220 2150");
codes[2] = new Array();
codes[2].push("2599 1957 1472 1472 231 155 421 421 83 2316 114 294 231 1309 83 320 294 583 83 421 421 83 2316 114 294 1472 554 2462 1146");
codes[3] = new Array();
codes[3].push("1651 1207 981 981 1110 13 1182 1182 1240 410 1110 1110 1649 1649 1649 981 1580 853 105 1182 105 1570 995 470 946 1580 436 226 825 995 1580 108 108 1570 853 1580 436 685 1570 981 470 946");
codes[4] = new Array();
codes[4].push("2489 1393 2117 2117 1127 2402 2015 2015 2350 2015 1960 2207 67 636 1980 1127 2004 2207 1927 1980 665 2207 2350 2221 1980 2117 1906 1960 667");
codes[5] = new Array();
codes[5].push("3077 2483 2590 2590 1551 1672 703 1820 1767 1516 1767 2926 1047 1774 703 959 757 1767 2590 2592 1047 2989");
codes[6] = new Array();
codes[6].push("907 821 695 695 431 826 197 431 854 535 179 650 332 826 197 695 624 175 353");
codes[7] = new Array();
codes[7].push("2507 1765 46 46 2416 548 2403 1583 646 161 2416 548 2403 1583 646 133 333 314 46 211 1841 1962");
codes[8] = new Array();
codes[8].push("2929 2033 593 1081 139 2020 1854 901 1927 220 1992 2540 1992");
codes[9] = new Array();
codes[9].push("1769 1891 80 280 103 1668 434 1084 80 280 103 1668 949 1664 110 100 1668 1222 534 1665 1653 109");
codes[10] = new Array();
codes[10].push("2047 1769 1293 1262 626 813 2014 886 871 23 493 685 493");
codes[11] = new Array();
codes[11].push("1843 2231 1664 234 1254 1269 222 820 485 1370 1254 73 1000 17 637 1269");
codes[12] = new Array();
codes[12].push("3071 1909 368 1540 1881 2106 1559 2257 1131 1690 2257 2885 1559 1540 1690 1559 1655 1540 1582 1582 1540 1540 823 1582 2445 840 411 80 1726 2252 2173 1690 1559 1356 1064 2179 2179 1064 1064 417 83 1881 1559 2173");
codes[13] = new Array();
codes[13].push("2867 3103 2137 1335 1335 1560 1778 47 47 2754 2754 2754 1503 1696 475 885 1335 885 2339 1571 2528 1675 1696 1422 1000 194 1571 1696 596 596 2339 475 1696 1422 249 2339 1503 2528 1675 47 2339 1335 2578 249 2339 567 47 885 1422 249 2339 1031 1503 2137 1335 475");
codes[14] = new Array();
codes[14].push("2077 1819 1157 566 1165 1151 1256 2021 1870 1598 1160 1160 1646 1151 1238 1256 1144 1998 492 2044 1913 492 1862");
codes[15] = new Array();
codes[15].push("2077 1843 380 1504 1512 984 1021 1342 790 1600 1504 380 1512 516 1065 1512 2019 1504 1342 984 1170 905 1342 380");
codes[16] = new Array();
codes[16].push("2323 2231 1930 664 1154 1432 1220 1000 2088 861 455 1154 1432 1154 861 861 606 206 1604 455 664 1220 606 1432 664 1154 2096 1636 1604 1432 1849 1060 206 1154 2096 1220 606 528 2096 606 1220 667 203 528");
codes[17] = new Array();
codes[17].push("2419 1817 191 2331 2204 1318 258 751 1946 258 2076 401 401 2331 2347 2076 80 2331 913 2347 401 2076 1138 1535 2331 913 2331 2347 751 751 80 446 401");
codes[18] = new Array();
codes[18].push("2759 1843 1496 1132 2659 2410 184 1652 46 285 664 1778 2659 2222 184 2659 1132 136 2410 126 5 126 1818 1398 126 285 1337 1652 1778 1132 136 1818 126 116 1312 1778");

var tableau_clef = new Array();

function decodage(crypto,indice,n,clef,courriel) {
	var index_clef = "'"+crypto+","+courriel+"'";
	//alert (index_clef);
	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 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;
}

