File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Projects/C++ Projects/Basic/Encryption and Decryption of Text Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Autor : Nemonet TYP
2
+ // Title: Encryption and Decryption project in C++
3
+ // PROJECT FOR C/C++ PROGRAMMING TUTORIAL
4
+
5
+
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 << " \n Please 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 << " \n Encrypted 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 << " \n Decrypted string: " << str << endl;
39
+ break ;
40
+
41
+ default :
42
+ cout << " \n Invalid Input !!!\n " ;
43
+ }
44
+ return 0 ;
45
+ }
You can’t perform that action at this time.
0 commit comments