File encryption error?

I can't seem to detect the txt file I want to encrypt using this code. Anything wrong here?

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
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream>
#include <fstream>

using namespace std;

void encryptFileData();
void decryptFileData();
int main()
{
   encryptFileData();
   decryptFileData();

   return 0;
}
void encryptFileData()
{
   char fileName[256];
   char secretFileName[256];
   cout <<"----------WELCOME TO ENCRYPTION-----------\n";
   cout << "Enter name of text file: (Original File) \n";
   cin>>fileName;

   cout << "Enter name of file to store encrypted data: (Secret File Name) \n";
   cin>>secretFileName;

   //Input file
   ifstream is;
   is.open(fileName);

   //Output file
   ofstream os;
   os.open(secretFileName);

   char c;
   cout<<"------Content of "<<fileName<<" is-------:\n";
   while (is.get(c))
   {
       cout <<c;
       //Adding 10 ACII value to original character to get ecrypted text
       char secretChar = c+10;
       os<<secretChar;
   }

   is.close();
os.close();
   cout<<"\n---------------------------------------------------\n";
   cout<<"Writing secret data to "<<secretFileName<<" completed\n";
}

void decryptFileData()
{
   char secretFileName[256];
   cout<<"----------WELCOME TO DECRYPTION-----------\n";
   cout << "Enter name of secret file:\n";
   cin>>secretFileName;

   //Input file
   ifstream is;
   is.open(secretFileName);

   char c;
   while (is.get(c))
   {
       //Decryption logic
       char originalChar = c -10;
       cout<<originalChar;
   }
   cout<<endl;
   is.close();

}
closed account (48T7M4Gy)
Try making a small program using the samples in this tutorial to read your file and print out a few lines.

http://www.cplusplus.com/doc/tutorial/files/
Topic archived. No new replies allowed.