Caesars Cipher Challenge

Caesars Cipher Challenge
0

#1

Tell us what’s happening:
Hi everyone,

So far I could get the decrypted strings, but I am not able to process only letters from A-Z and leave all the rest untouched. To be honnest, I have a problem with regular expressions.

Could anyone help me??

Your code so far

function rot13(str) { // LBH QVQ VG!
  var rotate13 = [];
  var i;
  var res;
  var replaced;
  
  for (i = 0; i < str.length; i++) {
    if (str.charCodeAt(i) + 13 > 90) {
      rotate13.push(String.fromCharCode(64 + str.charCodeAt(i) - 90 + 13));
    } else {
      rotate13.push(String.fromCharCode(str.charCodeAt(i) + 13));
    }
    res = rotate13.join("");
    replaced = res.replace(/-/g, " ");
  }
  return replaced;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0.

Link to the challenge:


#2

How about not adding or subtracting 13 from a character’s ascii code until you have first checked the ascii code for the character is between 65 and 90 (inclusive)?