Feeling F-ing Amazing!

I SOLVED “Caesars Cipher” IN 20 MINS WITHOUT LOOKING ANYTHING UP!

And I think my solution is pretty clean too.

I know to most of you this barely constitutes an “accomplishment”, but the Basic Algorithm Scripting challenges were kicking my rear. I only solved 3 or 4 of them without looking anything up and those all seemed like they were the easy ones of the bunch.

When I saw the instructions for “Caesars Cipher” I thought there was no way I’d be able to do it without some help, but I gave it a shot anyway and wrote the code at the bottom without any assistance or googling.

After struggling with many of the challenges it feels great to sit down, logic the problem out and code it cleanly on my own. Just thought I’d share.

Spoiler Warning for anyone who hasn’t done “Caesars Cipher” yet. .


function rot13(str) { // LBH QVQ VG!
  var coded = str.split("");
  var charC = [];
  var charCA = [];
  var decoded = [];
for (var i = 0; i < coded.length; i++) {
 
  charC.push(str.charCodeAt(i)); 

}
  for (var l = 0; l < charC.length; l++) {
  if (charC[l] === 32 || charC[l] > 91 || charC[l] < 65){
    charCA.push(charC[l]);
  }
    else if (charC[l] +13 >= 91) {
      charCA.push(charC[l]-13);
    }
    else {
    charCA.push(charC[l]+13); 
    }
}
  
    for (var m = 0; m < charCA.length; m++) {
  decoded.push(String.fromCharCode(charCA[m])); 

}
 
  
  return decoded.join('');
}

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

7 Likes

Grats, magic is more fun once you understand how to cast your own spells :wink:

1 Like

Wish I was there !! Congratulations !

1 Like

Congratulations @FletcherMartin, your perseverance is paying off :slight_smile:

2 Likes

To me I think this pretty much sums up what coding is about. I am a newbie and what attracts me most about the field is the ability to work on problems and arrive at solutions, in a very raw and concrete way. This is great for achieving moments of personal satisfaction. I am currently working on the tail end of the basic JavaScript section and I have had the same feeling you have described when figuring out some of the exercises. Cool stuff!

1 Like