-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
537 lines (505 loc) · 12.2 KB
/
main.cpp
File metadata and controls
537 lines (505 loc) · 12.2 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
// start of the program
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <map>
#include <windows.h>
int correct = 0;
using namespace std;
map<int, int> pass_factors;
class security_pass
{
protected:
string str;
int key;
string file_name;
int count = 0;
float percentage;
int cchoice;
int fchoice, factor_no;
int loop ;
public:
void factors();
void suggetion();
};
void security_pass::factors()
{ count=0 ;
loop = 0 ;
pass_factors.clear();
factor_no = 10;
do
{
cout << endl
<< "Enter use of which charecter for your password is not permited in your application// (website) " << endl;
if(loop!=0){
cout << endl
<< "0) remaining all are ok " << endl;
}
if(pass_factors.find(1)==pass_factors.end()){
cout << endl
<< "1) Uppercase alphabets " << endl;
}
if(pass_factors.find(2)==pass_factors.end()){
cout << endl
<< "2) lowercase alphabets " << endl;
}
if(pass_factors.find(3)==pass_factors.end()){
cout << endl
<< "3) special charecters " << endl;
}
if(pass_factors.find(4)==pass_factors.end()){
cout << endl
<< "4) Digits 0 to 1 " << endl;
}
if(loop==0){
cout << endl
<< "5) All above listed can include" << endl;}
cout << endl
<< "Enter the choices " << endl;
cin >> fchoice;
if (fchoice < 5 && fchoice != 0)
{
factor_no--;
pass_factors[fchoice] = 1;
loop++ ;
}
else if(fchoice!=5&&fchoice!=0){
cout<<endl<<"You entered wrong choice "<<endl ;
factors();
}
} while (fchoice != 0&&fchoice!=5);
}
void security_pass::suggetion()
{
cout << endl
<< "suggetion >>> TCltY#6uv12"
<< " " << endl;
}
class security_check : public security_pass
{
public:
void check_length();
void check_number();
void check_special();
void check_uppercase();
void check_lowercase();
void check_uppercase_repete();
void check_repete_number();
void check_repete_special();
void check_lowercase_repete();
void strength();
int option();
void getpass()
{
factors();
system("CLS");
cout << endl
<< "Now you enter your password " << endl;
cin >> str;
cout<<endl<<" Recomendetion "<<endl;
check_length();
}
};
int security_check::option()
{
cout << endl
<< "1) Try another combination " << endl;
cout << endl
<< "2) Back " << endl;
cout << endl
<< "Enter the choice" << endl;
cin >> cchoice;
if (cchoice == 1)
{
getpass();
}
else if (cchoice == 2)
{
correct = 1;
}
else
{
cout << endl
<< "wrong choice" << endl;
option();
}
}
void security_check ::strength()
{
percentage = (float)(100 * count) / factor_no;
if (percentage <= 15)
{
cout << endl
<< "Your password is too weak " << endl;
}
else if (percentage <= 30)
{
cout << endl
<< "your pass is weak " << endl;
}
else if (percentage <= 70)
{
cout << endl
<< "Your pass is moderate" << endl;
}
else if (percentage <= 90)
{
cout << endl
<< "Your pass is storng " << endl;
}
else if (percentage == 100)
{
cout << endl
<< "Your password is secure " << endl;
}
cout << endl
<< "Strength of password = " << percentage << " % " << endl;
}
void security_check::check_length()
{
int a = str.length();
if (a < 8)
{
cout << "Password is to short " << endl;
cout << endl
<< "TO make strong Password keep length atleast greter than 8 charectetrs " << endl;
count-- ;
}
else if (a > 30)
{
cout << "Password is two long " << endl
<< endl
<< " It will be difficult to remember for you " << endl;
}
else if (str.length() >= 13)
{
count += 2;
}
else
{
count++;
}
check_number();
}
void security_check::check_number()
{
if (pass_factors.find(4) == pass_factors.end())
{
int check = 0;
for (int i = 0; i < str.length(); i++)
{
if (str[i] >= 48 && str[i] <= 57)
{
check = 1;
}
}
if (check != 1)
{
cout << endl
<< "To make password strong try to include atleast one number " << endl
<< endl;
}
else
{
count++;
}
}
check_special();
}
void security_check::check_special()
{
if (pass_factors.find(3) == pass_factors.end())
{
int check = 0;
for (int i = 0; i < str.length(); i++)
{
if (str[i] >= 32 && str[i] <= 47 || str[i] >= 58 && str[i] <= 64 || str[i] >= 91 && str[i] <= 96 || str[i] >= 123 && str[i] <= 126)
{
check = 1;
}
}
if (check != 1)
{
cout << endl
<< "To make password strong try to include atleast one special charecter " << endl
<< endl;
}
else
{
count++;
}
}
check_uppercase();
}
void security_check::check_uppercase()
{
if (pass_factors.find(1) == pass_factors.end())
{
int check = 0;
for (int i = 0; i < str.length(); i++)
{
if (str[i] >= 65 && str[i] <= 90)
{
check = 1;
}
}
if (check != 1)
{
cout << endl
<< "To make password strong try to include atleast one uppercase later " << endl
<< endl;
count-- ;
}
else
{
count++;
}
}
check_lowercase();
}
void security_check::check_lowercase()
{
if (pass_factors.find(2) == pass_factors.end())
{
int check = 0;
for (int i = 0; i < str.length(); i++)
{
if (str[i] >= 97 && str[i] <= 122)
{
check = 1;
}
}
if (check != 1)
{
cout << endl
<< "To make password strong try to include atleast one lowercase later " << endl
<< endl;
count-- ;
}
else
{
count++;
}
}
check_uppercase_repete();
}
void security_check::check_uppercase_repete()
{
if (pass_factors.find(1) == pass_factors.end())
{
int check = 0;
for (int i = 0; i < str.length() - 2; i++)
{
if ((str[i] >= 48 && str[i] <= 57 )&& (str[i + 1] >= 48 && str[i + 1] <= 57))
{
if (str[i + 2] >= 48 && str[i + 2] <= 57)
{
check = 1;
}
}
}
if (check == 1)
{
cout << endl
<< "To make strong password try to avoid consecutely using uppercase charecter more than 2 times ";
count-- ;
}
else
{
count++;
}
}
check_lowercase_repete();
}
void security_check::check_lowercase_repete()
{
if (pass_factors.find(2) == pass_factors.end())
{
int check = 0;
for (int i = 0; i < str.length() - 2; i++)
{
if ((str[i] >= 97 && str[i] <= 122 )&& (str[i + 1] >= 97 && str[i + 1] <= 122))
{
if (str[i + 2] >= 97 && str[i + 2] <= 122)
{
check = 1;
}
}
}
if (check == 1)
{
cout << endl
<< "To make strong password try to avoid consecutely using lowercase charecter more than 2 times ";
}
else
{
count++;
}
}
check_repete_special();
}
void security_check::check_repete_special()
{
if (pass_factors.find(3) == pass_factors.end())
{
int check = 0;
for (int i = 0; i < str.length() - 2; i++)
{
if (str[i] >= 32 && str[i] <= 47 || str[i] >= 58 && str[i] <= 64 || str[i] >= 91 && str[i] <= 96 || str[i] >= 123 && str[i] <= 126)
{
if (str[i + 1] >= 32 && str[i + 1] <= 47 || str[i + 1] >= 58 && str[i + 1] <= 64 || str[i + 1] >= 91 && str[i + 1] <= 96 || str[i + 1] >= 123 && str[i + 1] <= 126)
{
check = 1;
}
}
}
if (check == 1)
{
cout << endl
<< "To make strong password try to avoid consecutely use of special charecter ";
}
else
{
count++;
}
}
check_repete_number();
}
void security_check::check_repete_number()
{
if (pass_factors.find(4) == pass_factors.end())
{
int check = 0;
for (int i = 0; i < str.length() - 2; i++)
{
if ((str[i] >= 48 && str[i] <= 57 ))
{if((str[i + 1] >= 48 && str[i + 1] <= 57)){
if (str[i + 2] >= 48 && str[i + 2] <= 57)
{
check = 1;
}}
}
}
if (check == 1)
{
cout << endl
<< "To make strong password try to avoid consecutely using numbers charecter more than 2 times ";
}
else
{
count++;
}
}
strength();
suggetion();
option();
}
class encrypt_decrypt : public security_pass
{
public:
void getfile_name();
void encryption();
void decryption();
};
void encrypt_decrypt::getfile_name()
{
cout << "Enter the file name \n"
<< endl;
cin >> file_name;
cout << "Enter the key" << endl;
cin >> key;
}
void encrypt_decrypt::encryption()
{
string out;
char k;
ifstream take;
take.open(file_name.c_str(), ios::binary);
ofstream give;
cout << endl
<< "Enter the name for Encrypted file" << endl;
cin >> out;
give.open(out.c_str(), ios::binary);
while (take.eof() == 0)
{
take >> noskipws >> k;
int temp = (k + key);
give << (char)temp;
}
take.close();
give.close();
}
void encrypt_decrypt::decryption()
{
char k;
string out;
ifstream take;
take.open(file_name.c_str(), ios::binary);
ofstream give;
cout << endl
<< "Enter the name for decrypted file" << endl;
cin >> out;
give.open(out.c_str(), ios::binary);
while (take.eof() == 0)
{
take >> noskipws >> k;
int temp = k - key;
give << (char)temp;
}
take.close();
give.close();
}
int main()
{
system("CLS");
system("color 74");
string pass;
int a;
int selected;
security_check c1;
encrypt_decrypt e1;
int choice;
do
{
cout << endl
<< "Choose required service" << endl;
cout << endl
<< "1)Password analyser." << endl;
cout << endl
<< "2)File encryption " << endl;
cout << endl
<< "3)File decryption " << endl;
cout << endl
<< "4)Exit" << endl;
cout << endl
<< "Enter the choice" << endl;
cin >> choice;
switch (choice)
{
case 1:
do
{
c1.getpass();
} while (correct != 1);
break;
case 2:
e1.getfile_name();
e1.encryption();
break;
case 3:
e1.getfile_name();
e1.decryption();
break;
case 4:
cout << endl
<< " !! Closing the application !!" << endl;
cout << endl
<< " <<Thank you for using our application>>" << endl;
exit(0);
break;
default:
cout<<"Wrong choice"<<endl;
}
} while (choice != 4);
return 0;
}