title: Using a vector of characters in C++ to program a Caesar Cipher
body: <p>I've been working a piece of code to encrypt a message using the Caesar Cipher. I've tried to keep it simple.</p>
  
  <pre><code>/* 
   * File:   main.cpp
   * Author: Skylar Croy
   *
   * Created on February 10, 2015, 11:50 AM
   * 
   * Purpose: To encrypt a message using the Caesar Cipher 
   */
  
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  
  using namespace std;
  int main(int argc, char *argv[]) {
  
      char letters[] = 
      {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; // Make a vector, letter, which equals [a b c ... z]
      int i, k; // i used in two loops, k used for shift 3 and mod calc
  
      for (i=0; i&lt;=25; i++) { // Run 26 times (1 for each letter)
  
          k = (i + 3) % 26; // Performs mod arth. with shift of 3
  
          letters[i+26] = letters[k]; // letter[i+26] = [d e f g ... c]
          // Note that letters = [a b c ... z d e f g....c]
               /* cout &lt;&lt; letters[i]; // This code shows that the operation in this for loop is functioning correctly
                  cout &lt;&lt; " ";
                  cout &lt;&lt; letters[i+26];
                  cout &lt;&lt; " \n"; */          
      }
  
      std:: string x; // declare string x
      cin &gt;&gt; x; 
  
          int string_length = x.size();
  
      for (i=0; i&lt;=(string_length-1); i++){ // individual characters of string x can be referenced by x[0] etc
  
          for (k=0; k&lt;=25; k++){ 
  
              if (x[i] == letters[k]) {
  
                              cout &lt;&lt; letters[k+26];
  
              }
          }
      } 
  return 0;
  }
  </code></pre>
  
  <p>For some reason when you try to encrypt a message with a w, x, y, or z it doesn't work and prints random trash. Not sure what is wrong. Any advice would be helpful. Thanks.</p>