Simple Encryption Program

I am trying to make a program that encrypts a text file. It will go through the file and turn a into b, b into c, and so on. I am having trouble though. this it what I have so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void encrypt()
{
    system("cls");
    system("title Encrypt -- Text File Encryptor");
    cout << "Enter path of the file you want to encrypt: ";
    string path;
    cin >> path;


    ofstream myfile;
    myfile.open ("path", ios::in | ios::binary);

    if (myfile.is_open())
    {
        cout << "File sucessfully opened." << endl;
    }

    else
    {
        cout << "ERROR opening file. Please try again." << endl << endl;
        system("pause");
        menu();
    }
}


but it doesn't work.

Thanks everybody
A few problems to begin with: (1) When opening a file, I believe you meant to use path as a variable and (2) I don't see why you need the binary mode when dealing with text files.

The method I would suggest reading [preferably to a array of characters(?)] the file's content (if it's very big) and going over every character, replacing it with the next one and finally write it all back to the file. For reading and writing you probably need to review the part about file IO in the tutorial/reference and getting the next char can be done by a function such as:

1
2
3
4
5
6
7
8
9
char nextCh(char ch) {
	if ((ch >= 'a' && ch < 'z') || (ch >= 'A' && ch < 'Z'))
		return ch+1;
	if (ch == 'z')
		return 'a';
	if (ch == 'Z')
		return 'A';
	return ch;
}
Topic archived. No new replies allowed.