I am needing to write a function to encrypt and decrypt. I am stuck on what the return type should be. As well as the types of arguments. So like for instance for a function to multiply x by y, you would have something like int doMultiply(int x, int y);. In my code, where it says type is what I need help on. Thanks.
#include <cstdlib>
#include <iostream>
#include <fstream>
usingnamespace std;
type doEncrypt(type input, type output);
type doDecrypt(type input, type output);
int main()
{
char response;
char input[32];
char output[32];
int x;
ifstream in_stream;
ofstream out_stream;
cout << "Would you like to ENCRYPT or DECRYPT (E or D)? ";
cin >> response;
while (response != 'e' && response != 'd' && response != 'D' && response != 'E')
{
cout << "Would you like to ENCRYPT or DECRYPT (E or D)? ";
cin >> response;
}
if(response == 'e' || response == 'E')
{
cout << "Enter the name of your input file you want to encrypt: ";
cin >> input;
cout << "Enter the name of the output file to write the ciphertext: ";
cin >> output;
}
if(response == 'd' || response == 'D')
{
cout << "Enter the name of your input file you want to decrypt: ";
cin >> input;
cout << "Enter the name of the output file to write the plaintext: ";
cin >> output;
}
in_stream.open(input);
out_stream.open(output);
if(in_stream.fail())
{
cout << "Input file opening failed.\n";
exit(EXIT_FAILURE);
}
if(out_stream.fail())
{
cout << "Output file opening failed.\n";
exit(EXIT_FAILURE);
}
in_stream.close();
out_stream.close();
return 0;
}
looks like string in, string out to me. Whether string is a char* std::string doesn't matter.
if you use xor, you can encrypt and decrypt in the same function, but the output might not be printable. Ive never had a need to make it printable, always just treated everything as binary.