Last active
November 24, 2022 06:40
-
-
Save jgresalfi/3fd39e0cf525980c115b4a34b9e0957f to your computer and use it in GitHub Desktop.
Write a function which takes a ROT13 encoded string as input and returns a decoded string.
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
//All letters to uppercase. Don't transform non-alphabetic characters (i.e. spaces, punctuation), but do pass them on. | |
function rot13(str) { | |
var codeArr = [], seq, final = ""; | |
for (var i = 0; i < str.length; i++) { | |
uCode = str.charCodeAt([i]); | |
if ((uCode > 64 && uCode < 78) || (uCode > 96 && uCode < 110)) { | |
uCode += 13; | |
codeArr.push(uCode); | |
} else if ((uCode > 77 && uCode < 91) || (uCode > 109 && uCode < 123)){ | |
uCode -= 13; | |
codeArr.push(uCode); | |
} else { codeArr.push(uCode); } | |
} | |
console.log(codeArr); | |
for (var j = 0; j < codeArr.length; j++) { | |
final += String.fromCharCode(codeArr[j]); | |
} | |
return final; | |
} | |
// Change the inputs below to test | |
rot13("SERR CVMMN!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment