Create a program that will accept a message from the user an

Create a program that will accept a message from the user and either encrypt ordecrypt it with the following algorithms: To encrypt: get the character you wish to encrypt find the index of that character in the alphabet array add the shift offset to the index add the increment to the index \"wrap around\" the new index so the result is between 0 and 29 find the character at the new index To decrypt: get the character you wish to decrypt find the index of that character in the alphabet array subtract the shift offset from the index subtract the increment from the index \"wrap around\" the new index so the result is between 0 and 29 find the character at the new index repeat steps 1 -6 for every shift offset The alphabet is , a-z(lowercase), , , and in that order. The increment should be +3 per letter position. Here is a sample message. Who said it?

Solution

//It is a c program to encrypt or decrypt your message
#include<stdio.h>
#include<string.h>
int find_index(char ch);
char find_char(int index);
main(){
   char message[100];
   int option,i,index;
   printf(\"Enter your message(small letters only):\");
   gets(message);
   printf(\"\ \ 1.Encryption\");
   printf(\"\ 2.decryption\");
   printf(\"\ \ \ Enter your option:\");
   scanf(\"%d\",&option);
   switch(option){
       case 1:
           //this code is for encryption
           i=0;
           while(message[i]!=\'\\0\'){
               index=find_index(message[i]);
               index=index+5;//adding shift offset to the index
               index=index+i+3;//adding increment to the index
               if(index>29)
                   index=index%10;
               message[i]=find_char(index);
               i++;
           }
           printf(\"\ The encryption of your message is:\");
           puts(message);
           break;
       case 2:
           //This code is for decryption
           i=0;
           while(message[i]!=\'\\0\'){
               index=find_index(message[i]);
               index=index-5;//substract shift offset from the index
               index=index-(i+3);//substract increment from the index
               while(index<0){
                   index=30+index;
               }
               message[i]=find_char(index);
               i++;
           }
           printf(\"\ The decryption of your message is:\");
           puts(message);
           break;
       default:
           printf(\"\ Invalid input\");
   }
   return 0;
}
//this function is to find the index of the character
int find_index(char ch){
   switch(ch){
       case \' \':
           return 0;
           break;
       case \'a\':
           return 1;
           break;
       case \'b\':
           return 2;
           break;
       case \'c\':
           return 3;
           break;
       case \'d\':
           return 4;
           break;
       case \'e\':
           return 5;
           break;
       case \'f\':
           return 6;
           break;
       case \'g\':
           return 7;
           break;
       case \'h\':
           return 8;
           break;
       case \'i\':
           return 9;
           break;
       case \'j\':
           return 10;
           break;
       case \'k\':
           return 11;
           break;
       case \'l\':
           return 12;
           break;
       case \'m\':
           return 13;
           break;
       case \'n\':
           return 14;
           break;
       case \'o\':
           return 15;
           break;
       case \'p\':
           return 16;
           break;
       case \'q\':
           return 17;
           break;
       case \'r\':
           return 18;
           break;
       case \'s\':
           return 19;
           break;
       case \'t\':
           return 20;
           break;
       case \'u\':
           return 21;
           break;
       case \'v\':
           return 22;
           break;
       case \'w\':
           return 23;
           break;
       case \'x\':
           return 24;
           break;
       case \'y\':
           return 25;
           break;
       case \'z\':
           return 26;
           break;
       case \'.\':
           return 27;
           break;
       case \'?\':
           return 28;
           break;
       case \',\':
           return 29;
           break;
       default:
           printf(\"\ Invalid input...\");
           break;
   }
}
//This function is to find the character of the index
char find_char(int index){
   switch(index){
       case 0:
           return \' \';
           break;
       case 1:
           return \'a\';
           break;
       case 2:
           return \'b\';
           break;
       case 3:
           return \'c\';
           break;
       case 4:
           return \'d\';
           break;
       case 5:
           return \'e\';
           break;
       case 6:
           return \'f\';
           break;
       case 7:
           return \'g\';
           break;
       case 8:
           return \'h\';
           break;
       case 9:
           return \'i\';
           break;
       case 10:
           return \'j\';
           break;
       case 11:
           return \'k\';
           break;
       case 12:
           return \'l\';
           break;
       case 13:
           return \'m\';
           break;
       case 14:
           return \'n\';
           break;
       case 15:
           return \'o\';
           break;
       case 16:
           return \'p\';
           break;
       case 17:
           return \'q\';
           break;
       case 18:
           return \'r\';
           break;
       case 19:
           return \'s\';
           break;
       case 20:
           return \'t\';
           break;
       case 21:
           return \'u\';
           break;
       case 22:
           return \'v\';
           break;
       case 23:
           return \'w\';
           break;
       case 24:
           return \'x\';
           break;
       case 25:
           return \'y\';
           break;
       case 26:
           return \'z\';
           break;
       case 27:
           return \'.\';
           break;
       case 28:
           return \'?\';
           break;
       case 29:
           return \',\';
           break;
       default:
           printf(\"\ Invalid input...\");
           break;
   }
}

 Create a program that will accept a message from the user and either encrypt ordecrypt it with the following algorithms: To encrypt: get the character you wish
 Create a program that will accept a message from the user and either encrypt ordecrypt it with the following algorithms: To encrypt: get the character you wish
 Create a program that will accept a message from the user and either encrypt ordecrypt it with the following algorithms: To encrypt: get the character you wish
 Create a program that will accept a message from the user and either encrypt ordecrypt it with the following algorithms: To encrypt: get the character you wish
 Create a program that will accept a message from the user and either encrypt ordecrypt it with the following algorithms: To encrypt: get the character you wish

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site