<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2.                                   **Pseudo code**
  3. Start
  4.    
  5.   Do
  6.  
  7.        Enter the number from between 2 to 16 in first line
  8.         this number indicates the length of cypher key
  9.  
  10.   While
  11.  
  12.        the number is less than 2 and more than 16, show error
  13.  
  14.   Do
  15.  
  16.        Enter the text from the word between 2 to 16 in second line
  17.            text should contain lower case alphabets only from a to z
  18.  
  19.   While
  20.  
  21.        the cypher key's letter is more or less than the input number, show error.
  22.  
  23.  
  24.        Enter the number from 4 to 256 for plain text in thrid line
  25.        this number indicates the length of plain text for fourth line
  26.  
  27.   Do
  28.  
  29.       error if the plain text number is less or more than between 4 to 256
  30.  
  31.   While
  32.  
  33.       plain text number should be between 4 to 256
  34.  
  35.      Enter the text from word between 4 to 256
  36.       text's word count must be same as the number entered in third line
  37.       including space
  38.    
  39.   Do
  40.      
  41.      Plain text should be between 4 to 256
  42.            text should contain lower case alphabets only from a to z
  43.      
  44.   While
  45.  
  46.      plain text should be a words between 4 to 256 including space
  47.    
  48.    Performing the encryption position N to target value N+1
  49.    
  50.      target value of N change with the subsitute value of N+1
  51.                                 substitue value is the first key of cypher key
  52.    
  53.    Performing the encryption position N to target value N+1
  54.    
  55.      substitue the second position of cypher key of input in second line
  56.      with second last target value
  57.      
  58.    
  59.      
  60. >>  On the output plain text, all the instance of the target value will
  61.          replace with the substitution.
  62.  
  63. >>  the number of first line should be the number of substitution on the output
  64.  
  65. >>  if the word count is not as a same number input, it will show an error
  66.  
  67. >>  if the first letter of fourth line words is entered different than the word in second line,
  68.     it will show an error.
  69.  
  70. End
  71.  
  72. */
  73.  
  74. #include <stdio.h>
  75. #define MAX_SIZE 16
  76.  
  77. int main()
  78. {
  79.     int x,y,N,M,i,clen;
  80.     char cipher[MAX_SIZE];
  81.     char plain_text[256],temp[256],temp1[16][256];
  82.    
  83.    
  84.     //Taking input length of cipher key from 2 to 16
  85.     printf("Please enter length of cipher key between 2 to 16: ");
  86.     scanf("%d",&x);
  87.    
  88.     //Checking cipher key character length in between 2 to 16
  89.     if(x<2 || x>16){
  90.         do{
  91.             printf("\nEntered cipher key length %d is not in between 2 to 16, Enter again: ",x);
  92.             scanf("%d",&x);
  93.         }while(x<2 || x>16);
  94.     }
  95.    
  96.     //Taking actual cipher key.
  97.     printf("\nEnter cipher key of length %d :",x);
  98.     scanf("%s",cipher);
  99.     if(x!=strlen(cipher)){
  100.         do{
  101.             printf("\nEntered Cipher key length is %d it must be %d, Enter again:",strlen(cipher),x);
  102.             scanf("%s",cipher);
  103.         }while(x!=strlen(cipher));
  104.     }
  105.    
  106.    
  107.    
  108.     //Taking input length of plain text from 4 to 256
  109.     printf("\nPlease enter length of plain text between 4 to 256: ");
  110.     scanf("%d",&y);
  111.    
  112.     //Checking plain text character length in between 4 to 256
  113.     if(y<4 || y>256){
  114.         do{
  115.             printf("\nEntered plain text length %d is not in between 4 to 256, Enter again: ",y);
  116.             scanf("%d",&y);
  117.         }while(y<4 || y>256);
  118.     }
  119.    
  120.     //Taking actual plain text.
  121.     printf("\nEnter plain text of length %d: " ,y);
  122.     //scanf ("%s", plain_text);
  123.     scanf (" %[^\n]", plain_text);
  124.    
  125.     //fgets (plain_text,100,stdin);
  126.     //scanf("%s",plain_text);
  127.     if(y!=strlen(plain_text)){
  128.         do{
  129.             printf("\nEntered Plain Text length is %d it must be %d, Enter again: ",strlen(plain_text),y);
  130.             //scanf ("%s", plain_text);
  131.             scanf (" %[^\n]", plain_text);
  132.         }while(y!=strlen(plain_text));
  133.     }
  134.    
  135.  
  136.    
  137.     strcpy(temp,plain_text);
  138.     clen=strlen(cipher);
  139.    
  140.    
  141.     //Performing the encryption position N to target value N+1
  142.     for(N=0; N<strlen(plain_text); N++){
  143.         if(temp[0]==cipher[N]){
  144.             plain_text[N]=cipher[N+1];
  145.         }
  146.     }
  147.    
  148.     printf("\nStep 1 Substitute %c with %c",cipher[0],cipher[1]);
  149.     printf("\n%s",plain_text);
  150.    
  151.    
  152.     //Performing the encryption position second position of cipher to target value second last
  153.     for(M=1; M<clen-1; M++){
  154.         for(N=0; N<strlen(plain_text); N++){
  155.             if(cipher[M]==temp[N]){
  156.                 plain_text[N]=cipher[M+1];
  157.             }
  158.         }
  159.         printf("\nStep %d substitute %c with %c", M+1, cipher[M],cipher[M+1]);
  160.         printf("\n%s",plain_text);
  161.     }
  162.  
  163.  
  164.    
  165.        
  166.        
  167.        
  168.     //End of cipher key pointer
  169.     for(N=0; N<strlen(plain_text); N++){   
  170.         if(cipher[clen-1]==temp[N]){
  171.             plain_text[N]=cipher[0];
  172.         }
  173.     }
  174.        
  175.     printf("\nStep %d Substitute %c with %c",clen,cipher[clen-1],cipher[0]);
  176.     printf("\n%s",plain_text)
  177.    
  178.  
  179.     return 0;
  180. }