-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
265 lines (248 loc) · 6.05 KB
/
main.cpp
File metadata and controls
265 lines (248 loc) · 6.05 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include<iostream>
#include<windows.h>
#include<mmsystem.h>
#include<string>
#include<cmath>
#include <stdlib.h>
#include<fstream>
using namespace std;
SetColor(int value)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),value);
}
class Login
{
private:
string username = "officer007";
string password = "crypto";
bool accessGranted;
public:
string Var_user;
string Var_password;
Login()
{
accessGranted = 0;
}
void loginFunction()
{
SetColor(10);cout << "\nUsername: ";
SetColor(12);cin >> Var_user;
if(Var_user!=username)
{
PlaySound(TEXT("alert.wav"),NULL,SND_SYNC);
cout << "\nInvalid username!!!\nThe program is terminated!" << endl;
exit(0);
}
SetColor(10);cout << "Password: ";
SetColor(12);cin >> Var_password;
if(Var_password!=password)
{
PlaySound(TEXT("alert.wav"),NULL,SND_SYNC);
cout << "\nInvalid password!!!\nThe program is terminated!" << endl;
exit(0);
}
cout << endl;
}
};
class header
{
public:
header()
{
SetColor(10);cout << "\n\t\t\t ---------------------------------------" << endl;
cout << "\t\t\t | PAKISTAN ARMY CRYPTOGRAPHY SOFTWARE |" << endl;
cout << "\t\t\t ---------------------------------------" << endl;
cout << endl;
SetColor(12);cout << "\n\n \t\t\t>>>Important Note<<<" << endl;
cout << "_____________________________________________________________________________________________________________________________________"<<endl<<endl;
cout << "1) Due to security concerns you have only one attempt to enter a username and password." << endl;
cout << "2) If username or password is wrong the software is terminated automatically." << endl << endl;
cout << "_____________________________________________________________________________________________________________________________________"<<endl;
cout << endl;
}
};
class graphics
{
private:
char x = 220;
public:
graphics()
{
for(int i=0; i<35; i++)
{
cout << x;
if(i<10)
Sleep(300);
if(i>=10 && i<20)
Sleep(150);
if(i>=10)
Sleep(25);
}
cout << " 100%";
}
};
void reverse_cipher(string &str)
{
int n = str.length();
for (int i = 0; i < n / 2; i++)
{
swap(str[i], str[n - i - 1]);
}
}
void S_cipher(string &str)
{
char cipher_key = 'S';
int len = str.length();
for (int i = 0; i < len; i++)
{
str[i] = str[i] ^ cipher_key;
}
}
void XOR_cipher(string &str)
{
char key[] = "ObjectOrientedProgramming";
int len = str.length();
int j = 0;
for (int i = 0; i < len; i++)
{
str[i] = str[i] ^ key[i];
}
}
int main()
{
header h1;
Login obj1, obj2;
obj1.loginFunction();
char again ='Y';
while (again == 'y' || again == 'Y')
{
int i=0;
int x=0;
string str;
str.clear();
SetColor(10);cout << "\nPlease choose following options: " << endl;
cout << "1. Encrypting the file." << endl;
cout << "2. Decrypting the file." << endl;
cout << "\n\nEnter your choice: ";
SetColor(12);cin >> x;
cout << endl;
switch(x)
{
case 1:
{
SetColor(10);string filename1;
cout << "Enter the file name that you want to encrypt: ";
SetColor(12);cin >> filename1;
cout << endl;
ifstream infile(filename1.c_str(), ios::binary);
if(infile.is_open())
{
while(getline(infile,str))
{
reverse_cipher(str);
for(i=0; i<str[i] ;i++)
{
str[i]=str[i]+3;
}
S_cipher(str);
for(i=0; i<str[i] ;i++)
{
str[i]=str[i]+6;
}
XOR_cipher(str);
for(i=0; i<str[i] ;i++)
{
str[i]=str[i]+7;
}
/*cout << "\nEncryped string: " << str << endl;*/
ofstream outFile("encryptedfile.txt",ios::app | ios::binary);
if(outFile.is_open())
{
outFile << str <<endl;
}
outFile.close();
}
infile.close();
cout << "Encrypting File..." << endl;
SetColor(10);graphics obj1;
Sleep(800);
SetColor(12);cout << "\n\nFile is encrypted successfully!!!" << endl;
cout << "\n\nSaving encrypted data in file..." << endl;
SetColor(10);graphics obj2;
Sleep(800);
SetColor(12);cout << "\n\nEncryptedfile.txt is created successfully!!!\n" << endl;
PlaySound(TEXT("congo.wav"),NULL,SND_SYNC);
}
else
{
cout << "File is not found!!!" << endl;
}
break;
}
case 2:
{
system("cls");
header h2;
cout << endl;
cout << "\nNote: This feature is locked. Kindly enter username and password again."<<endl;
obj2.loginFunction();
SetColor(10);string filename2;
cout << "Enter the file name that you want to decrypt: ";
SetColor(12);cin >> filename2;
cout << endl;
ifstream decfile(filename2.c_str(), ios::binary);
if(decfile.is_open())
{
while(getline(decfile,str))
{
for(i=0; i<str[i] ;i++)
{
str[i]=str[i]-7;
}
XOR_cipher(str);
for(i=0; i<str[i] ;i++)
{
str[i]=str[i]-6;
}
S_cipher(str);
for(i=0; i<str[i] ;i++)
{
str[i]=str[i]-3;
}
reverse_cipher(str);
/*cout << "\nDecryped string: " << str << endl;*/
ofstream endFile("decryptedfile.txt",ios::app | ios::binary);
if(endFile.is_open())
{
endFile << str <<endl;
}
endFile.close();
}
decfile.close();
cout << "Decrypting File..." << endl;
SetColor(10);graphics obj3;
Sleep(800);
SetColor(12);cout << "\n\nFile is decrypted successfully!!!" << endl;
cout << "\n\nSaving decrypted data in file..." << endl;
SetColor(10);graphics obj4;
Sleep(800);
SetColor(12);cout << "\n\nDecryptedfile.txt is created successfully!!!\n" << endl;
PlaySound(TEXT("congo.wav"),NULL,SND_SYNC);
}
else
{
cout << "File is not found!!!" << endl;
}
break;
}
default:
{
cout << "\n Invalid Input!!!" << endl;
}
}
SetColor(10);cout << "\nRun Software again? (y/n): ";
SetColor(12);cin >> again;
}
system("pause");
return 0;
}