-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencryption.cpp
99 lines (77 loc) · 1.71 KB
/
encryption.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
//encryption
//Libraries used:
#include <iostream>
#include <conio.h>
#include<windows.h>
using namespace std;
#define QUIT 9
int Menu() {
int num=0;
bool validChoice;
validChoice = false;
while (!validChoice) {
system("cls");
cout << "1. Encryption" << endl;
cout << "2. Decryption" <<endl;
cout << "Press 9 to Quit" <<endl;
cin >> num;
if (num>=1 && num<=QUIT) // Ensures choice is within the range of menu options
validChoice = true;
else {
cout << "Invalid selection. Try again." <<endl;
}
system("cls");
}
return num;
}
//Main Function:
int main () {
//Var
int num=0,i=0, location=0;
string text;
string Text[5];
string Ciph[5]={"A%dsn2#ty1$","ES785#@123$","99983%$dg","B%dss2**23","qwrt@smn43*"};
for (i=0;i<5;i++) {
Text[i] = " ";
}
while (num!=9) {
num=Menu();
if (num==1) {
cout << "Please enter the text you would like to encrypt: (Words cannot have spaces) " <<endl;
cin >> text;
for (i=0;i<5;i++) {
if (Text[i]==" ") {
Text[i]=text;
location=i;
break;
}
else {
cout << "ENCRYPTING..." <<endl;
Sleep(110);
}
}
cout << "Encrypted message: " << Ciph[location] <<endl;
system("pause");
}
else {
if (num==2) {
cout << "Please enter the text you would like to decrypt: " <<endl;
cin >> text;
for (i=0;i<5;i++) {
if (text==Ciph[i]) {
location=i;
break;
}
else {
cout << "DECRYPTING..." <<endl;
Sleep(100);
}
}
cout <<"Decrypted message: ";
cout << Text[location]<<endl;
system("pause");
}
}
}
return 0;
} //End of program