I've been trying to get this simple encryption application to work, but i keep getting the wrong output.
I get the wrong number of characters in the text-file, but i've gone through the code a hundred times, and i can't find the error. What have i done wrong?Code:#include <iostream>
#include <fstream>
#include <string>
#include "clscr.h"
int main()
{
std::ofstream outputfile ("C:\\WINDOWS\\XOR\\DATA.txt", std::ios::trunc);
std::string key, plainText, cipherText;
int i = 0, j = 0, k = 0, l = 0;
std::cout << "Enter key: ";
std::cin >> key;
std::cout << std::endl << "Enter plaintext: ";
std::cin >> plainText;
clscr();
i = plainText.length();
l = key.length();
for(j; j < i; j++)
{
cipherText[j] = plainText[j] ^ key[k];
k++;
if(k == (l+1))
{
k = 0;
}
}
for(j = 0; j < i; j++)
{
outputfile << cipherText[j];
}
std::cin.ignore();
outputfile.close();
}