freecCodeCampBonfireCaesarCipher

function rot13(str) { // LBH QVQ VG! parenthese 0 var elencoAlpha = ['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']; var elencoRota13 = []; for (var i = 0; i <26; i++) {//1 elencoRota13.push(elencoAlpha[(i + 13) % 26]); }//-1 var strRot13 = ""; for (var j = 0; j < str.length; j ++) {//1 if (str[j].toLowerCase() == str[j].toUpperCase()) {strRot13 = strRot13.concat(str[j]);}//2;-2 else {//2 for (var k = 0; k < 26; k ++) {//3 if (str[j] === elencoAlpha[k]) {strRot13 = strRot13.concat(elencoRota13[k]);}//4;-4 }//-3 }//-2 } return strRot13; } // Change the inputs below to test rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.") ;
Changer les lettres seulement;
faire un decalage de 13, c'est facile jusqu' a 13, apres a partir de 14 on utilise le modulo 26 (%26)
pour les non lettres, on les definit comme termes dont la majuscule est egale a la minuscule.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.