title: XOR Encryption in C++
body: <p>I am trying to implement a simple XOR Encryption using a number, of type <code>long</code>. Unfortunately, some of the numbers return some symbols that decrypting them gives a whole different text than the one entered. </p>
  
  <p>For example, encrypting a text <code>'hello world'</code> with the key <code>'5105105105'</code> returns this <code>'��'</code>. To decrypt it back with the same key, it returns this <code>'&gt;nl wor&gt;nl'</code>. I am not sure why is it doing this. </p>
  
  <p>This is my code:</p>
  
  <pre><code>string encDec(string str, long key) {
      string output = str;
  
      for (int i = 0; i &lt; str.size(); i++)
          output[i] = str[i] ^ key;
  
      return output;
  }
  </code></pre>
  
  <p>What am I doing wrong here?</p>