Last active
October 9, 2020 11:50
-
-
Save theoctober19th/e7ae6d78609ecbf3bc672fb1c843f74d 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> | |
#include <cstring> | |
using namespace std; | |
int main() | |
{ | |
int choice; | |
char alphabets[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
char key[]= "bdafzLPmNRxTcVQX+UWSKMpFknHy*EGIqZhtvYDgrCulAwoBsjei_"; | |
char encrypted_message[50]; | |
char decrypted_message[50]; | |
do{ | |
cout << "1.Encrypt the message.\n2.Decrypt the message.\n3.Quit" << endl; | |
cout << "Enter your choice:"; | |
cin >> choice; | |
cin.get(); | |
switch(choice){ | |
case 1: | |
cout << "Enter your secret message:" << endl; | |
cin.getline(decrypted_message,50); | |
for (size_t i = 0; i < strlen(decrypted_message); ++i) | |
for (size_t j = 0; j < strlen(alphabets); ++j) | |
{ | |
if (alphabets[j] == decrypted_message[i]) | |
{ | |
encrypted_message[i] = key[j]; | |
break; | |
} | |
} | |
cout << "The encrypted message is : " << encrypted_message << endl; | |
break; | |
case 2: | |
cout << "Enter your secret message:" << endl; | |
cin.getline (encrypted_message,45); | |
for (size_t i = 0; i < strlen(encrypted_message); ++i) | |
for (size_t j = 0; j < strlen(key); ++j) | |
if (key[j] == encrypted_message[i]) | |
{ | |
decrypted_message[i] = alphabets[j]; | |
break; | |
} | |
cout <<"The decrypted message is:" << decrypted_message << endl; | |
break; | |
case 3: | |
cout << "Goodbye..." << endl; | |
break; | |
default: | |
cout << " Invalid choice try again."; | |
} | |
} while(choice!= 3); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment