mlarrubia
11/29/2018 - 4:39 PM

ROT13

function rot13(str) { // LBH QVQ VG!
  
  var temp =  "";

  for(var i = 0; i < str.length; i++){
    if(str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90){      
      var code = str.charCodeAt(i);
      if(code >= 78){
        var letter = Math.abs(90 - code - 12) + 65; 
        temp += String.fromCharCode(letter);
      }
      else{        
        var letter = code + 13;        
        temp += String.fromCharCode(letter);
      }
    }      
    else{      
      temp += str[i];
    }    
  }
  return temp;
}

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