Skip to content

Instantly share code, notes, and snippets.

@rodpoblete
Last active June 6, 2017 03:00
Show Gist options
  • Save rodpoblete/926d0d6f93987f3371468d82fb27db62 to your computer and use it in GitHub Desktop.
Save rodpoblete/926d0d6f93987f3371468d82fb27db62 to your computer and use it in GitHub Desktop.
Caesars Cipher Decifrar mensaje encriptado - FCC [257]
function rot13(str) {
var num = 0, str2 = ""; // declaro las variables vacias
for (var i = 0; i < str.length; i++) { // ciclo para recorrer el string
num = str.charCodeAt(i); // asigno el numero de caracter unicode a num
if (num >= 65) { // si variable es mayor que A Unicode sumo + 13
num += 13;
}
if (num > 90) { // si variable es mayor que 90 Z Unicode resto 26 (-13 * 2)
num -= 26;
}
str2 += String.fromCharCode(num); // convierto los valores numericos en letras
}
return console.log(str2);
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment