Function

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace 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;
}
Last edited on
Hi @test1234,
I suppose that would be void for return type and char array for parameters,
regards! :D
But the input and output file that user enters would not be a character. It would be for example text1 for input and text2 for output
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.

Topic archived. No new replies allowed.