Created
August 3, 2020 00:37
-
-
Save ctkqiang/0faa43ea91c953d3e84b9700030e340d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() | |
| { | |
| int i, x; | |
| char str[100]; | |
| cout << "Please enter a String: \t"; | |
| cin >> str; | |
| cout << "\n Please Choose The Following Options: \n"; | |
| cout << "[1] ENCRYPT STRING. \n"; | |
| cout << "[2] DECRYPT STRING. \n"; | |
| cin >> x; | |
| switch (x) | |
| { | |
| case 1: | |
| for (i = 0; (i < 100 && str[i] != '\0'); i++) | |
| { | |
| str[i] = str[i] + 2; //the key for encryption is 3 that is added to ASCII value | |
| } | |
| cout << "\nEncrypted string: " << str << endl; | |
| break; | |
| case 2: | |
| for (i = 0; (i < 100 && str[i] != '\0'); i++) | |
| { | |
| str[i] = str[i] - 2; //the key for encryption is 3 that is subtracted to ASCII value | |
| } | |
| cout << "\nDecrypted string: " << str << endl; | |
| break; | |
| default: | |
| cout << "\nInvalid Input !!!\n"; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment