title: How do I convert xor encryption from using std::string to just char or char *?
body: <p>So essentially with the libraries that i'm working with I cannot use std::string, as it uses a somewhat depreciated version of C++ I need to convert this xor function from using std::string to just using char or char *. I have been trying but I cannot figure out what I am doing wrong, as I get an error. Here is the code:</p>
  
  <pre><code>string encryptDecrypt(string toEncrypt) {
      char key[] = "DSIHKGDSHIGOK$%#%45434etG34th8349ty"; //Any chars will work
      string output = toEncrypt;
  
      for (int i = 0; i &lt; toEncrypt.size(); i++)
          output[i] = toEncrypt[i] ^ key[i % (sizeof(key) / sizeof(char))];
  
      return output;
  }
  </code></pre>
  
  <p>If anyone could help me out, that would be great. I am unsure as to why I cannot do it by simply changing the strings to char *. </p>
  
  <p>Edit:</p>
  
  <p>What I have tried is:</p>
  
  <pre><code>char * encryptDecrypt(char * toEncrypt) {
      char key[] = "DSIHKGDSHIGOK$%#%45434etG34th8349ty"; //Any chars will work 
      char * output = toEncrypt; 
      for (int i = 0; i &lt; sizeof(toEncrypt); i++) 
          output[i] = toEncrypt[i] ^ key[i % (sizeof(key) / sizeof(char))]; 
      return output; 
  }
  </code></pre>
  
  <p>Please note I am not trying to convert an std::string to char, I simply cannot use std::string in any instance of this function. Therefore, my question is not answered. Please read my question more carefully before marking it answered...</p>