-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
124 lines (96 loc) · 3.48 KB
/
main.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include<iostream>
#include<fstream>
#include<stdio.h>
using namespace std;
void starttext(){
cout<<R"(
/$$$$$$$$ /$$
| $$_____/ | $$
| $$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$
| $$$$$ | $$__ $$ /$$_____/ /$$__ $$| $$ | $$ /$$__ $$|_ $$_/ /$$__ $$ /$$__ $$
| $$__/ | $$ \ $$| $$ | $$ \__/| $$ | $$| $$ \ $$ | $$ | $$ \ $$| $$ \__/
| $$ | $$ | $$| $$ | $$ | $$ | $$| $$ | $$ | $$ /$$| $$ | $$| $$
| $$$$$$$$| $$ | $$| $$$$$$$| $$ | $$$$$$$| $$$$$$$/ | $$$$/| $$$$$$/| $$
|________/|__/ |__/ \_______/|__/ \____ $$| $$____/ \___/ \______/ |__/
/$$ | $$| $$
| $$$$$$/| $$
\______/ |__/)";
cout<<endl<<endl<<endl;
cout<<"\nQuick note";
cout<<"\n----------";
cout<<"\n+ You will be asked for file name and file extension";
cout<<"\n+ Enter txt in file extension to encrypt the .txt file";
cout<<"\n+ Enter en in file extension to decrypt the .en file";
cout<<"\n+ <filename>.txt file will be encrypted, <filename>.en file will be decrypted";
cout<<"\n+ The files must be present in the root of the code or exe";
cout<<endl<<endl;
}
void encrypt(string filename){
ifstream fin;
fin.open(filename + ".txt");
if(fin.fail()){
cout<<"\nFATAL ERROR 02 := Unknown file `"<<filename<<".txt`\nFile doesn't exist. Read Quick Note!!";
}
else{
ofstream fout;
fout.open(filename + ".en");
char ch;
while(!fin.eof()){
fin.get(ch);
fout<<(char)(ch+69);
}
cout<<"\nFile ENCRYPTED successfully";
filename += ".txt";
const char *charfilename = &filename[0];
fin.close();
fout.close();
if( remove(charfilename) != 0 )
perror("\nError deleting the .txt file");
else
puts("\n.txt file successfully deleted\n.en file created" );
}
}
void decrypt(string filename){
ifstream fin;
fin.open(filename + ".en");
if(fin.fail()){
cout<<"\nFATAL ERROR 02 := Unknown file `"<<filename<<".en`\nFile doesn't exist. Read Quick Note!!";
}
else{
ofstream fout(filename + ".txt");
char ch;
while(!fin.eof()){
fin.get(ch);
fout<<(char)(ch-69);
}
cout<<"\nFile DECRYPTED successfully";
filename += ".en";
const char *charfilename = &filename[0];
fin.close();
fout.close();
if( remove(charfilename) != 0 )
perror("\nError deleting the .en file");
else
puts("\n.en file successfully deleted\n.txt file created" );
}
}
int main(){
begin:
cout << "\033[2J\033[1;1H";
starttext();
string filename;
cout<<"\nEnter file name:: ";
cin>>filename;
string fileext;
cout<<"Enter file extension:: ";
cin>>fileext;
if(fileext == "txt") encrypt(filename);
else if(fileext == "en") decrypt(filename);
else cout<<"\nFATAL ERROR 01 := Unsupported file extension `."<<fileext<<"`\nOnly txt and en are supported. Read Quick Note!!";
char ch;
cout<<"\n\n\nEnter q to exit, any other character to restart:: ";
cin>>ch;
if(ch == 'q');
else goto begin;
return 0;
}