# Cipher challenge

**URL:** <https://forum.freecodecamp.org/t/cipher-challenge/411343>\
**Category:** General\
**Created:** [July 23, 2020, 11:35am UTC](https://forum.freecodecamp.org/t/cipher-challenge/411343 "2020-07-23T11:35:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Linda8](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/linda8/32/170282_2.png) [@Linda8](https://forum.freecodecamp.org/u/Linda8)\
**Post date:** [July 23, 2020, 11:35am UTC](https://forum.freecodecamp.org/t/cipher-challenge/411343/1 "2020-07-23T11:35:59Z")

</div>

Hello, I think I have experienced the worst day today. A break will do me good, no progress for 3hours.

```auto
function rot13(str) {

const alpha ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

let result = "";

while(str.length > 0){

for(let i = 0; i <= 25; i++){

  if(alpha[i] === str[0] && (i > 13)) {

    result += alpha(i-13);

  } if( alpha[i] === str[0] && (i < 13)){

    result += alpha( i + 13);

  } 

}

  return result;

}

}

console.log

```

---

<div class="post-metadata">

**Author:** ![geraldombuthia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/geraldombuthia/32/132306_2.png) [@geraldombuthia](https://forum.freecodecamp.org/u/geraldombuthia)\
**Post date:** [July 23, 2020, 11:55am UTC](https://forum.freecodecamp.org/t/cipher-challenge/411343/2 "2020-07-23T11:55:25Z")

</div>

It happens to the best, keep striving , take a break and then keep striving.  
Do you need help?

---

<div class="post-metadata">

**Author:** ![Linda8](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/linda8/32/170282_2.png) [@Linda8](https://forum.freecodecamp.org/u/Linda8)\
**Post date:** [July 24, 2020, 7:38am UTC](https://forum.freecodecamp.org/t/cipher-challenge/411343/3 "2020-07-24T07:38:30Z")

</div>

Hello, I need serious help. Woke up to crack it, but woe unto me, I still at the same point.

---

<div class="post-metadata">

**Author:** ![geraldombuthia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/geraldombuthia/32/132306_2.png) [@geraldombuthia](https://forum.freecodecamp.org/u/geraldombuthia)\
**Post date:** [July 24, 2020, 8:12am UTC](https://forum.freecodecamp.org/t/cipher-challenge/411343/4 "2020-07-24T08:12:00Z")

</div>

hey first, why are you using two loops?  
i think just one would be okay to iterate through it.  
this challenge requires you to basically replace a character for another character 13 characters ahead, so you need a way to check this characters and then replace them with characters 13 places ahead.  
use of an array would be great at this point and much easier.  
You could have alpha as an array of alphabets and then str being an input, you can then iterate through the str check the alphabet and then check the index of the same alphabet in the alpha array and return the alphabet in that index +13, or conversely you can have alpha as an object where an the key-value pairs are an alphabet: alphabet 13 characters ahead. After checking you can push them to the results

---

<div class="post-metadata">

**Author:** ![Linda8](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/linda8/32/170282_2.png) [@Linda8](https://forum.freecodecamp.org/u/Linda8)\
**Post date:** [July 24, 2020, 8:36am UTC](https://forum.freecodecamp.org/t/cipher-challenge/411343/5 "2020-07-24T08:36:36Z")

</div>

I will appreciate because for me it is making sense, resulted to manual shifting of the letters. But this code can’t run.

---

<div class="post-metadata">

**Author:** ![Linda8](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/linda8/32/170282_2.png) [@Linda8](https://forum.freecodecamp.org/u/Linda8)\
**Post date:** [July 24, 2020, 8:43am UTC](https://forum.freecodecamp.org/t/cipher-challenge/411343/6 "2020-07-24T08:43:23Z")

</div>

In my second attempt I have done away with the while loop, yet still not running.

---

<div class="post-metadata">

**Author:** ![tejambsnks](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tejambsnks/32/154593_2.png) [@tejambsnks](https://forum.freecodecamp.org/u/tejambsnks)\
**Post date:** [July 24, 2020, 8:52am UTC](https://forum.freecodecamp.org/t/cipher-challenge/411343/7 "2020-07-24T08:52:46Z")

</div>

4 th line and 7 th line seems wrong

---

<div class="post-metadata">

**Author:** ![geraldombuthia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/geraldombuthia/32/132306_2.png) [@geraldombuthia](https://forum.freecodecamp.org/u/geraldombuthia)\
**Post date:** [July 24, 2020, 10:12am UTC](https://forum.freecodecamp.org/t/cipher-challenge/411343/8 "2020-07-24T10:12:33Z")

</div>

Try using arrays, you can make result to be an empty array where you will push the new letters

---

<div class="post-metadata">

**Author:** ![Linda8](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/linda8/32/170282_2.png) [@Linda8](https://forum.freecodecamp.org/u/Linda8)\
**Post date:** [July 26, 2020, 3:36pm UTC](https://forum.freecodecamp.org/t/cipher-challenge/411343/9 "2020-07-26T15:36:40Z")

</div>

Hello, I took a break. This is a headache  
const cipherArr = [  
[B, O],

[C, P],

[D, Q],

[E, R],

[F, S],

[G, T],

[H, U],

[I,V],

[J, W],

[K, X],

[L, Y],

[M, Z]

];

Function rot13 = (str) {

let newStr = str.split("");

for(var i = 0; i \< newStr.length;i++){

newStr[i] === cipherArr[i][0]) {

newStr[i] = cipherArr[i][1];

}

else if( newStr[i] ===cipherArr[i][0]){

newStr[i]=cipherArr[i][0];

}

}

}

return newStr.join("");

console.log(rot13());

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:45pm UTC](https://forum.freecodecamp.org/t/cipher-challenge/411343/10 "2021-06-01T18:45:25Z")

</div>

Closed on June 1, 2021, 6:45pm UTC


