Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- //#include<array>
- #include<cstdlib>
- #include<fstream>
- #include<ctime>
- #include<chrono>
- using namespace std;
- char alphabets[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m',
- 'n','o','p','q','r','s','t','u','v','w','x','y','z',' ' };
- //create an array of numbers 0 to 25
- int numbers[27] = { '@','7','1','#','$','9','0','6','!','*','(',')','~','^','8','&','/','3',';','<','2','5','?','[','4',']',' ' };
- char* encrypt(char* msg, int total_msg, char* cip, int total_cip);
- char* decrypt(char* cip, int total_cip, char* pln, int total_pln);
- int main() {
- //create an array of alphabets a to z
- char message[1000] = { '\0'};
- char cipher[1000] = { '\0' };
- char plain_text[1000] = { '\0' };
- cout << "Enter the message to be encrypted: ";
- cin.getline(message, 1000);
- //encrypting the message
- encrypt(message, 1000, cipher, 1000);
- cout << "The encrypted message is: " << cipher << endl;
- decrypt(cipher, 1000, plain_text, 1000);
- cout << "The decrypted message is: " << plain_text << endl;
- return 0;
- }
- char* encrypt(char * msg, int total_msg,char * cip, int total_cip) {
- for (int i = 0; i < total_msg; i++) {
- if (msg[i] == '\0') {
- break;
- }
- for (int j = 0; j < 27; j++) {
- if (msg[i] == alphabets[j]) {
- cip[i] = numbers[j];
- break;
- }
- }
- }
- return cip;
- }
- char* decrypt(char* cip, int total_cip, char* pln, int total_pln) {
- for (int i = 0; i < total_cip; i++) {
- if (cip[i] == '\0') {
- break;
- }
- for (int j = 0; j < 27; j++) {
- if (cip[i] == numbers[j]) {
- pln[i] = alphabets[j];
- break;
- }
- }
- }
- return pln;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement