I think I am close to figuring this out.
Object is to take a string of "encrypted" characters and decipher them to actual words. Perhaps my code isn't very elegant right now, I'll get there, but I CAN get the beginning 'str = "SERR PBQR PNZC"' to return the correct ASCII code using charCodeAt(), add or subtract 13 as needed, and concat that into strArray--I know, it's not an array. But I can't get strArray to become an array, so I can pass it to String.fromCharCode(null, strArray); to have it return the correct deciphered text.
My code is below:
function rot13(str) { // LBH QVQ VG!
var strArray = '';
//var right = [70, 82, 69, 69, 32, 67, 79, 68, 69, 32, 67, 65, 77, 80];
//used above variable with String.fromCharCode.apply(null, right); and it worked.
for(var i = 0; i < str.length; i++){
//console.log(str.charCodeAt(i));
if(str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 77) {
strArray = strArray.concat(str.charCodeAt(i) + 13, ' ');
} else if(str.charCodeAt(i) >= 78) {
strArray = strArray.concat(str.charCodeAt(i) - 13, ' ');
} else {
strArray = strArray.concat(str.charCodeAt(i), ' ');
}
}
return strArray;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Any help will be greatly appreciated.