Skip to content

Commit 7f31d70

Browse files
Update main.cpp
1 parent 68d0038 commit 7f31d70

File tree

1 file changed

+40
-40
lines changed
  • Projects/C++ Projects/Basic/Encryption and Decryption of Text

1 file changed

+40
-40
lines changed

Projects/C++ Projects/Basic/Encryption and Decryption of Text/main.cpp

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,43 @@
33
// PROJECT FOR C/C++ PROGRAMMING TUTORIAL
44

55

6-
#include <iostream>
7-
using namespace std;
8-
9-
int main()
10-
{
11-
int i, x;
12-
char str[100];
13-
14-
cout << "Please enter a string\t";
15-
cin >> str;
16-
17-
cout << "nPlease choose following options\n";
18-
cout << "1 = Encrypt the string\n";
19-
cout << "2 = Decrypt the string\n";
20-
cin >> x;
21-
22-
//using switch case statements
23-
switch(x)
24-
{
25-
//first case for encrypting a string
26-
case 1:
27-
for(i = 0; (i < 100 && str[i] != ' '); i++)
28-
str[i] = str[i] + 2; //the key for encryption is 3 that is added to ASCII value
29-
30-
cout << "\nEncrypted string: " << str << endl;
31-
break;
32-
33-
//second case for decrypting a string
34-
case 2:
35-
for(i = 0; (i < 100 && str[i] != ' '); i++)
36-
str[i] = str[i] - 2; //the key for encryption is 3 that is subtracted to ASCII value
37-
38-
cout << "\nDecrypted string: " << str << endl;
39-
break;
40-
41-
default:
42-
cout << "n\Invalid Input !!!\n";
43-
}
44-
return 0;
45-
}
6+
#include <iostream>
7+
using namespace std;
8+
9+
int main()
10+
{
11+
int i, x;
12+
char str[100];
13+
14+
cout << "Please enter a string:\t";
15+
cin >> str;
16+
17+
cout << "\nPlease choose following options:\n";
18+
cout << "1 = Encrypt the string.\n";
19+
cout << "2 = Decrypt the string.\n";
20+
cin >> x;
21+
22+
//using switch case statements
23+
switch(x)
24+
{
25+
//first case for encrypting a string
26+
case 1:
27+
for(i = 0; (i < 100 && str[i] != '\0'); i++)
28+
str[i] = str[i] + 2; //the key for encryption is 3 that is added to ASCII value
29+
30+
cout << "\nEncrypted string: " << str << endl;
31+
break;
32+
33+
//second case for decrypting a string
34+
case 2:
35+
for(i = 0; (i < 100 && str[i] != '\0'); i++)
36+
str[i] = str[i] - 2; //the key for encryption is 3 that is subtracted to ASCII value
37+
38+
cout << "\nDecrypted string: " << str << endl;
39+
break;
40+
41+
default:
42+
cout << "\nInvalid Input !!!\n";
43+
}
44+
return 0;
45+
}

0 commit comments

Comments
 (0)