Streams and files

I'm having a problem understanding what this problem wants me to do and what encrypt and decrypt are? Can anyone help please!

1. A function char EncChar (char C, int j, int flag) to receive a character (C) and its index (j) in the message. If flag = 0, the character is plain and we intend to encrypt it. In this case, the function returns the encrypted character by adding a displacement di obtained from a character Ki in a secret key in the form of a string of length (n) characters.

2. A function void encfile (string infile, string outfile) to encrypt/decrypt a whole text file of characters and write the result to another file. This function will call the character function EncChar for each input character.

3. A main function to:
• receive the input and output file names from the user.
• Set a flag = 0 to encrypt and flag = 1 to decrypt.
• Call the file encryption function encfile.
Here is a little skeleton to get you started:
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
#include <iostream>
#include <string>

using namespace std;

const int ENCRYPT = 0;
const int DECRYPT = 1;

int UserOption;

char EncChar (char C, int j, int flag);
void encfile (string infile, string outfile);
void GetFileNames (string &infile, string &outfile);
void GetOption ();

int main ()
{
  string infile, outfile;

  GetFileNames (infile, outfile);
  GetOption ();
  encfile (infile, outfile);

  system ("pause");
  return 0;
}

char EncChar (char C, int j, int flag)
{
  // TODO encode the char c and return it
  return C;
}
void encfile (string infile, string outfile)
{
  // TODO encode od decode infile depending on the global var UserOption
}
void GetFileNames (string &infile, string &outfile)
{
  // TODO get the filenames for infile and outfile from the user 
  // and store them in infile and outfile
}
void GetOption ()
{
  // TODO ask the user if he want's to encode or decode thefile
  // and store the choice in UserOption
}
Thank you for your help! Just one more question so I make sure that I understand right: The user will give me a string for example "hello" and i have to return it as "elohl" or other way around, right?
As far as I understand you have to encrypt / decrypt a file so the user will give you the filenames - see Nr. 3.
Topic archived. No new replies allowed.