Skip to content

Commit f3108c5

Browse files
committed
Program ROT13 Cypher
1 parent 71d8bfe commit f3108c5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

rot13.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function rot13(str) { // LBH QVQ VG!
2+
var cadenaLegible=[];
3+
var suma=0;
4+
for(var cont=0; cont < str.length; cont++){
5+
//console.log("Entrada: ")
6+
if(str[cont]>= "A" && str[cont]<="M"){
7+
suma = 13;
8+
}else if (str[cont]>"M" && str[cont]<="Z"){
9+
suma = -13;
10+
}
11+
if (str[cont]>="A" && str[cont]<="Z"){
12+
cadenaLegible.push(String.fromCharCode(str.charCodeAt(cont)+suma));
13+
}else{
14+
cadenaLegible.push(str[cont]);
15+
}
16+
}
17+
console.log(cadenaLegible);
18+
return cadenaLegible.join("");
19+
}
20+
21+
// Change the inputs below to test
22+
rot13("SERR PBQR PNZC");

0 commit comments

Comments
 (0)