Cesars Cipher Quesiton

Hi im stuck on the cesars cipher problem and not sure how to proceed. I can get the characters to decode but they are in the wrong order. When there are more one letter inputted to the string it add the 2nd character the beginning instead of the end.

function rot13(str) {
  const cipher = {
    'A': 'N',
    'B': 'O',
    'C': 'P',
    'D': 'Q',
    'E': 'R',
    'F': 'S',
    'G': 'T',
    'H': 'U',
    'I': 'V',
    'J': 'W',
    'K': 'X',
    'L': 'Y',
    'M': 'Z',
    'N': 'A',
    'O': 'B',
    'P': 'C',
    'Q': 'D',
    'R': 'E',
    'S': 'F',
    'T': 'G',
    'U': 'H',
    'V': 'I',
    'W': 'J',
    'X': 'K',
     'Y': 'L',
     'Z': 'M'   

  }


let newArr = str.split('')
let testString= []
 for (let [key, value] of Object.entries(cipher)) {
for(let i = 0; i < newArr.length; i++){
 if(newArr[i] == key){
  testString += value
  console.log(testString)
  
 
}
}

}
  

  }


console.log(rot13("AB"));

I do know this… the code is not complete, when I try to add the values to string such that str = “SERR” it returns “REEF” instead of “FREE”

Please check the post I have edited to better explain my problem. I did not mean to say that return was the problem my was problem that it returns in the wrong order and I don’t understand why.

No thanks Ill just work it out a different way.

You really should give a basic roadmap of your thoughts about how to go about solving this issue. It will help people guide you, and give you decent instructions to follow yourself so you don’t get lost in code.

If you give us a roadmap we can point out where you took a wrong turn. Otherwise you might end up going round and round in a loop more then you need to.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.