Looks like you are doing the same assignment that i was assigned.... if you are using Gaddis textbook than it would be helpful to read Chapter 12(Pg.673)...here's what's wrong:
1) If you are trying to take "plain.txt" --> than encrypt it as "coded.txt" --> decrypt the file in output as "decoded.txt" ???? Start with pseudo code before you jump in....
2) Here's an e.g. of code that reads string "Line by Line" from a file as you are trying preserve the format of "plain.txt":
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
string raw_data;
ifstream inFile ("plain.txt", ios::in);
if (inFile)
{
getline(inFile, raw_data); // Read first line
while (inFile) // While last read operation successful, continue
{
cout << raw_data << endl; //Display last read line
getline(inFile, raw_data); // Read next line
// Figure out What to do here use coder777's code than you have to do something else
// To preserve your output....
}
inFile.close(); // Close the file
}
else cout << "Error:...\n";
3) You are in right path just remember each each character's is in it's ASCII value so you can add subtract an int to it.
// advance the key iterator, wrapping to begin.
if(++ keyIterator == encryptionKey.end())
keyIterator = encryptionKey.begin();
}
return ret;
}
int main()
{
// variable-length key of randomness, used for both encryption and decryption.
std::vector<BYTE> key;
key.push_back(0x55);
key.push_back(0xae);
key.push_back(0x8c);
key.push_back(0x14);