Skip to content

Instantly share code, notes, and snippets.

@mekicha
Last active May 9, 2023 09:32
Show Gist options
  • Save mekicha/e1225ab9ff59bf869a75f6e12233664d to your computer and use it in GitHub Desktop.
Save mekicha/e1225ab9ff59bf869a75f6e12233664d to your computer and use it in GitHub Desktop.
Caesars Cipher FREE CODE CAMP Write a function which takes a ROT13 encoded string as input and returns a decoded string. All letters will be uppercase. Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.
function rot13(str) {
var arr = [];
for(var i = 0; i < str.length; i++){
var code = 0;
code = str.charCodeAt(i);
if(code < 65){
arr.push(String.fromCharCode(code));
} else{
code = code + 13;
if(code > 90){
code = code % 90 + 65 -1;
arr.push(String.fromCharCode(code));
}
else{
arr.push(String.fromCharCode(code));
}
}
}
return arr.join("");
}
@Amir-Kermanshahani
Copy link

Good Job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment