title: Error implementing Caesar Cipher Using C++
body: <p>I am trying to implement Caesar Cipher using C++. The directions are to use this file which is already encrypted: </p>
  
  <pre><code>5
  Asi ymj rtrjwfymjx tzylwfgj.
  Aqq rnrxd bjwj ymj gtwtlwtajx
  Dni ldwj fsi ldrgqj ns ymj bfgj.
  Tbfx gwnqqnl fsi ymj xnymjd ytajx
  </code></pre>
  
  <p>The number 5 represents the shift that is applied to the text. I have to decode the Caesar ciphered text and reverse the lines as in put line 4 in line 1's position and line 3 in line 2's. The first letter of each line does not need to be decoded (the uppercase letters).</p>
  
  <p>The text should look like this after running the program:</p>
  
  <pre><code>Twas brillig and the sithey toves
  Did gyre and gymble in the wabe.
  All mimsy were the borogroves
  And the momerathes outgrabe.
  </code></pre>
  
  <p>As of right now, I have this code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  char decipher (char c, int shift);
  
  int main(){
      //declare variables
      char c;
      string deciphered = "";
      int shift;
      vector &lt;string&gt; lines;
  
      //ask for filename and if not found, keep trying
      ifstream inFile;
      string filename;
      cout &lt;&lt; "What is the name of the file? ";
      cin &gt;&gt; filename;
      inFile.open(filename);
      while (!inFile){
          cout &lt;&lt; "File not found. Try again: ";
          cin &gt;&gt; filename;
          inFile.open(filename);
      }
  
      //find shift from file
      inFile &gt;&gt; shift;
  
      //get lines from file
      inFile &gt;&gt; noskipws;
      while (inFile &gt;&gt; c){
          char decipheredChar = decipher (c, shift);
          deciphered += decipheredChar;
      }
      cout &lt;&lt; deciphered;
  
  }
  
  char decipher (char c, int shift){
      string letters = "abcdefghijklmnopqrstuvwxyz";
      if (c == 'T'){
          return c;
      }
      else if (c == 'D'){
          return c;
      }
      else if (c == 'A'){
          return c;
      }
      else if (c == ' '){
          return c;
      }
      else {
          int currentPosition = letters.find(c);
          int shiftedPosition = currentPosition - shift;
          if (shiftedPosition &lt; 0){
              shiftedPosition = 26 + shiftedPosition;
          }
          char shifted = letters[shiftedPosition];
          return shifted;
      }
  }
  </code></pre>
  
  <p>The result I'm getting is this:</p>
  
  <pre><code>uAnd the momerathes outgrabeuuAll mimsy were the borogrovesuDid gyre and gymble in the wabeuuTwas brillig and the sithey tovesu
  </code></pre>
  
  <p>How do I get rid of the u's and also separate the words by line? I have an idea of reversing the lines using a vector and using a loop counting backwards but I'm not sure how to get to there yet. Please help. Thank you.</p>