Im working on this little text encrypter/decrypter in C++, but im having some trouble with the encrypting part.
Here is what i have so far:
Encrypter:
So as you can see, the progam accepts input, casts it to ASCII numeric values, so that it is not easily readable, and outputs it to a text file. No security revolution, im aware of that, but that's irelevant :)Code:#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream algorithm1("Algorithm1.txt", ios::app);
char message[40];
int index = 0;
if(!algorithm1)
{
cout <<"Couldn't Open File" << endl;
cin.get();
exit(1);
}
cout << "Please enter a word with no whitespaces: ";
cin >> message;
for( index = 0 ; index < 40 ; index++)
{
algorithm1 << (int)message[index] << " ";
}
algorithm1 << endl;
algorithm1.close();
}
I'm also aware that C-Style arrays are outdated, but im just trying to get this to work, will probably use real strings once i figure out how i do.
The code compiles and runs beatifully, but the output in the text file is way off.
For example, if i entered "C++" in the Encrypter. The text file contains:
"67 43 43 0 -112 22 -11 119 -128 55 61 0 78 22 -11 119 -24 6 61 0 106 22 -11 119 0 0 0 0 -120 55 61 0 104 35 36 0 72 -1 34 0 "
The first 3 numbers are actually correct, and will display "C++" when decrypted, but the rest is utter nonsense?
Im guessing this is because im printing a mostly empty array, am i right? I'm not really into Vectors at all, so if i HAVE to use vectors in my program, could you please show me a complete example of how i could do it. Although i would prefer if there was some other way to fix it.
Thanks in advance
Neo