Last active
June 6, 2017 03:00
-
-
Save rodpoblete/926d0d6f93987f3371468d82fb27db62 to your computer and use it in GitHub Desktop.
Caesars Cipher Decifrar mensaje encriptado - FCC [257]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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