I didn’t find a link to post Caesars Cipher solution so I made my own. The cool thing is that I though of this one before following the video, and usually I’ll get stuck trying to think of solutions. Then I lost the code so had to try to recreate it by memory! Hope it makes sense.
function rot13(str) {
let decodedStr = "";
for(let i = 0; i < str.length; i++) {
const char = str[i];
if(/[A-Z]/.test(char)) {
let code = str.charCodeAt(i);
if(char > 'M') {
code -= 13;
} else {
code += 13;
}
decodedStr += String.fromCharCode(code);
} else {
decodedStr += char;
}
}
return decodedStr;
}
console.log(rot13("SERR PBQR PNZC"));