Last active
May 9, 2023 09:32
-
-
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.
This file contains 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 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(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good Job!