title: Not receiving output file in my decryption program
body: <p>I've been struggling with this for a few days now, but I just haven't been able to figure it out. I'm pretty new to C++ and I'm making a simple decoding program for my own encoding. But for some odd reason, I'm not getting an output. I'm coding in the CodeBlocks IDE and then run it through PowerShell, I've tried running through regular command prompt but this doesn't help. Does anyone have a solution? Thank you very much, Abe.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  std::string base64_decode(const std::string &amp;s);
  std::string DecryptB64 (std::string s);
  
  const std::string &amp;SALT1 = "hidden";
  const std::string &amp;SALT2 = "hidden";
  const std::string &amp;SALT3 = "hidden";
  const std::string &amp;BASE64_CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  
  int main(int argc, char **argv)
  {
      if(argc != 3)
          return std::cout &lt;&lt; "Programma heeft twee argumenten nodig, input en output!" &lt;&lt; std::endl, 2;
      std::string in (argv[1]), out (argv[2]);
      std::ifstream fi (in);
      if(!fi)
          return std::cout &lt;&lt; "Kan input bestand '" &lt;&lt; in &lt;&lt; "' niet lezen!" &lt;&lt; std::endl, 3;
      std::string data;
      fi &gt;&gt; data;
      if(!fi)
          return std::cout &lt;&lt; "Input bestand '" &lt;&lt; in &lt;&lt; "' corrupted!" &lt;&lt; std::endl, 4;
      data = DecryptB64(data);
      std::ofstream fo (out);
      if (!fo)
          return std::cout &lt;&lt; "Kan output bestand '" &lt;&lt; out &lt;&lt; "' niet lezen!" &lt;&lt; std::endl, 5;
      fo &lt;&lt; data;
      std::cout &lt;&lt; "Decoden is gelukt!" &lt;&lt; std::endl;
      return 0;
  }
  
  std::string base64_decode(const std::string &amp;s)
  {
          std::string ret;
          std::vector&lt;int&gt; vec(256, -1);
          for (int i = 0; i &lt; 64; i++)
              vec [BASE64_CODES[i]] = i;
          int val = 0, bits = -8;
          for (const auto &amp;c : s)
              {
                  if (vec[c] == -1) break;
                  val = (val &lt;&lt; 6) + vec[c];
                  bits += 6;
  
                  if (bits &gt;= 0)
                      {
  
                          ret.push_back(char((val &gt;&gt; bits) &amp; 0xFF));
                          bits -= 8;
                      }
              }
  
          return ret;
  }
  
  std::string DecryptB64 (std::string s)
  {
      s = s.erase (7, 1);
      s = s.erase (1, 1);
      s = base64_decode (s);
      s = s.substr (SALT2.length() + SALT3.length());
      s = s.substr (0, s.length() - SALT1.length());
      s = base64_decode (s);
      s = s.substr (0, s.length() - SALT1.length());
      s = s.erase (7, SALT3.length());
      s = s.substr (SALT1.length());
      s = s.substr (0, s.length() - SALT2.length() - SALT3.length());
      return s;
  }
  </code></pre>
  
  <p>Here is the encryption code:</p>
  
  <pre><code>#ifndef BASE64_H
  #define BASE64_H
  
  #include &lt;vector&gt;
  #include &lt;string&gt;
  
  namespace Base64
  {
      std::string base64_encode(const std::string &amp;);
  
      const std::string &amp;SALT1 = ":EG:::ZXQL";
      const std::string &amp;SALT2 = ":ZAerPLgfs";
      const std::string &amp;SALT3 = "decrypt696";
  
  
      std::string EncryptB64 (std::string s)
      {
          s = SALT1 + s + SALT2 + SALT3;
          s = base64_encode (s);
          return s;
      }
  
      const std::string &amp;BASE64_CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz0123456789+/";
  
      std::string base64_encode(const std::string &amp;s)
      {
          std::string ret;
          int val = 0;
          int bits = -6;
          const unsigned int b63 = 0x3F;
  
          for(const auto &amp;c : s)
          {
              val = (val &lt;&lt; 8) + c;
              bits += 8;
              while(bits &gt;= 0)
              {
                  ret.push_back(BASE64_CODES[(val &gt;&gt; bits) &amp; b63]);
                  bits -= 6;
              }
          }
  
          if(bits &gt; -6)
              ret.push_back(BASE64_CODES[((val &lt;&lt; 8) &gt;&gt; (bits+8)) &amp; b63]);
  
          while(ret.size() % 4)
              ret.push_back('=');
  
          return ret;
      }
  }
  
  #endif // BASE_64
  </code></pre>
  
  <p>And the code that uses the encryption functions:</p>
  
  <pre><code>    std::string WriteLog(const T &amp;t)
  {
      std::string path = GetPath(true);
      Helper::DateTime dt;
      std::string name = dt.GetDateTimeString("_") + ".log";
  
      try
      {
          std::ofstream file(path + name);
          if(!file) return "";
          std::ostringstream s;
          s &lt;&lt; "[" &lt;&lt; dt.GetDateTimeString() &lt;&lt; "]" &lt;&lt; std::endl &lt;&lt; t &lt;&lt; std::endl;
          std::string data = Base64::EncryptB64(s.str());
          file &lt;&lt; data;
          if(!file)
              return "";
          file.close();
          return name;
      }
      catch(...)
      {
          return "";
      }
  }
  </code></pre>
  
  <p>Also, here are the contents of an encrypted file to decrypt with the program:</p>
  
  <pre><code>OkVHOjo7WlhRTFsyMS5xMz5zMDE6IDE2OjI1OjE2XQpbVF2bUl2bSV2bT22bSF2bSl2bUl2bSV2bT22bVF2bUl2bTV2bTl2bQl2bT22bVF2bSV2bUl2bQl2bTl2bUl2bVF2bT22bSV2bQl2bTl2bT22bUl2bVF2bSV2bQl2bTl2bUl2bVF2bSV2bT22bSl2bTl2bQl2bVF2bUl2bSV2bT22bQl2bSl2bUl2bVF2bSV2bQl2bSl2bUl2bVF2bT22bSV2bQl2bSl2bTV2bR22bSV2bVF2bVV2bRF2bTF2bSF2bR22bQl2bVV2bUl2bSV2bRl2bT22bTF2bRF2bS22bR22bSF2bRl2bRF2bR22bSF2bRF2bUl2bS22bTF2bR22bSF2bQl2bRl2bRF2bWF2bSl2bTF2bR22bSF2bS22bTF2bSl2bSF2bQl2bUl2bT22bVV2bSF2bSl2bQl2bTl2bSV2bUl2bRV2bVF2bQl2bSF2bSl2bVl2bTl2bVV2bSV2bRl2bR22bS22bR22bQl2bSF2bRl2bSV2bVV2bR22bSF2bRl2bSV2bVV2bVF2bTF2bRF2bSF2bRl2bVV2bR22bQl2bTl2bSl2bRl2bSV2bVV2bRF2bSF2bVF2bUl2bVV2bSl2bTF2bUl2bRF2bR22bSF2bSl2bVF2bUl2bRF2bT22bTF2bSF2bVV2bSl2bRF2bUl2bVF2bSV2bT22bVV2bSF2bUl2bRF2bVF2bVV2bSV2bSF2bSl2bUl2bVF2bVV2bSV2bRF2bSl2bSF2bSl2bVF2bVV2bSV2bUl2bRF2bSF2bTF2bVV2bVF2bUl2bRF2bSF2bVF2bRF2bVV2bUl2bSV2bSF2bVF2bRF2bUl2bSV2bSF2bVF2bSF2bRF1KOlpBZXJQTGdmc3RlY4J6cHQ3OTY=
  </code></pre>