FCC Bonfirm Algorithm: Caesar Cipher Challenge

FCC Bonfirm Algorithm: Caesar Cipher Challenge
0.0 0

#1

Morning guys I am currently doing the caesars cipher challenge and I am stuck in trying to convert the unicode back to a string to complete the decryption. I tried using the fromCharCode() method to convert the uni code to a string but it isn’t working. my Code is shown below:

     

    function rot13(str)     { 
   
      var cipherText = '';

      var newCipher = [];
  
      var newString = str.split('');
 
 
      for (i = 0; i < str.length; i++) {
    
        if (newString[i].charCodeAt() >= 65 && newString[i].charCodeAt() <= 90){
      
           newString[i].charCodeAt();
    
      
        if (newString[i].charCodeAt() < 78) {
      
           newCipher[i] = (newString[i].charCodeAt() + 13);
      
      
        }
       else if (newString[i].charCodeAt() >= 78) {
      
           newCipher[i] = (newString[i].charCodeAt() - 13);
         }
    
        cipherText = newCipher.join(' ');  
     
     
        }

    
  
      }
  
      return cipherText;
 
  
 
  
  
     }

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

Please help me guy

#2

You should read the documentation for charCodeAt(). It takes an argument and returns a value.


#3

Thanks Ariel. I have already figured it out. I would love some feedback from this code

‛‛‛
function rot13(str) {
var cipherText = ‘’;

     var newCipher = [];

     var newString = str.split('');

     var cipher;


     for (i = 0; i < str.length; i++) {

          if (newString[i].charCodeAt() >= 65 &&                  newString[i].charCodeAt() <= 90){
  
               newString[i].charCodeAt();
   

  
        if (newString[i].charCodeAt() < 78) {
  
             newCipher[i] = (newString[i].charCodeAt() + 13);
  
  
         }
        else if (newString[i].charCodeAt() >= 78) {
  
                newCipher[i] = (newString[i].charCodeAt() - 13);
  
   }

       cipherText = String.fromCharCode.apply(String, newCipher);
 
      }

        if (newString[i].charAt(length).charCodeAt() < 65) {
  
             cipher = cipherText.replace(/\0/g, ' ') + newString[i].charAt(length);

   
      }

        else {
              cipher = cipherText.replace(/\0/g, ' ');

      }


      }

     return cipher;
  }

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

‛‛‛