<mosaic.cnfolio.com>
PROGRAM
  1. /*Pseudo code:
  2.               START
  3.                    Enter length of cipher key from 2 to 16
  4.                      IF
  5.                         the cipher key length is less than 2 or more than 16
  6.                      DO
  7.                         Error! need to be between 2 to 16
  8.                      WHILE
  9.                         the cipher key length is less than 2 or more than 16
  10.                          
  11.                    Taking actual cipher key
  12.                    Enter cypher key length
  13.                      IF
  14.                          cipher key is not equal to stringlenth(cipher)
  15.                      DO
  16.                          Error! cipher key lenth is not between 2 to 16
  17.                      WHILE
  18.                          cipher key is not equal to stringlenth(cipher)
  19.                          
  20.                        
  21.                    Enter length of plain text from 4 to 256
  22.                      IF
  23.                          the plain text length is less than 4 or more than 256
  24.                      DO
  25.                          Error! need to be between 4 to 256
  26.                      WHILE
  27.                          the plain text length is less than 4 or more than 256
  28.                  
  29.                    Taking actual plain text
  30.                    Enter plain text length
  31.                      IF
  32.                          plain text  is not equal to stringlenth(plain_text)
  33.                      DO
  34.                          Error! plain text length is not between 4 to 256
  35.                      WHILE
  36.                          plain text  is not equal to stringlenth(plain_text)
  37.                          
  38.                    
  39.                    Performing the encryption position N to targer value N+1
  40.                      FOR
  41.                         position N is zero; and is less than stringlenth(plain_text), add 1 at position N
  42.                      IF
  43.                          temp[0] is equal to the cipher[N]
  44.                            assign the value of plain_text[N] to the cipher[N]
  45.                            
  46.                    Performing the encryption position second position of cipher to targer value second last
  47.                      FOR
  48.                         position M is 1; and is less then clen<-1; add 1 at position M
  49.                        
  50.                      FOR
  51.                         position N is 0; and is less than stringlenth(plain_text), add 1 at position N
  52.                      IF
  53.                         cipher[M] is equal to the temp[N]
  54.                           assign the value of plain_text[N] to the cipher[M+1]
  55.                          
  56.                    End of cipher key pointer
  57.                      FOR
  58.                         position N is zero; and is less than stringlenth(plain_text), add 1 at position N
  59.                      IF
  60.                         cipher[clen-1] is equal to temp[N]
  61.                            assign the value of plain_text to the cipher[0]
  62.                      
  63.                      
  64.                   END
  65.               */
  66.  
  67.  
  68.  
  69.  
  70. #include <stdio.h>
  71. #include <string.h>      /*header file for the standard string library functions*/
  72. #define MAX_SIZE 16
  73.  
  74. int main()
  75. {
  76.     int key;
  77.     int text;
  78.     int N,P,clen;
  79.     char cipher[MAX_SIZE];
  80.     char plain_text[256];
  81.     char temp[256];
  82.    
  83.    
  84.     /*Inserting the input length of cipher key which must be from 2 to 16*/
  85.     printf("***Entering the length of cipher key between 2 to 16***");
  86.     scanf("%d",&key);
  87.    
  88.     /*Checking cipher key character length in between 2 to 16*/
  89.     if(key<2 || key>16){
  90.         do{
  91.             printf("\n***ERROR!*** Entered cipher key length %d is not in between 2 to 16",key);
  92.             scanf("%d",&key);
  93.         }while(key<2 || key>16);
  94.     }
  95.    
  96.     /*inserting the chosen cipher key*/
  97.     printf("\nEntered cipher key of length is %d",key);
  98.     scanf("%s",cipher);
  99.     if(key!=strlen(cipher)){
  100.         do{
  101.             printf("\n***ERROR!*** Entered Cipher key length is %d it must be %d",strlen(cipher),key);
  102.             scanf("%s",cipher);
  103.         }while(key!=strlen(cipher));
  104.     }
  105.    
  106.    
  107.     /*Inserting the input length of plain text which must be from 4 to 256*/
  108.     printf("\n***Entering length of plain text between 4 to 256*** ");
  109.     scanf("%d",&text);
  110.    
  111.     /*Checking plain text character length in between 4 to 256*/
  112.     if(text<4 || text>256){
  113.         do{
  114.             printf("\n***ERROR!*** Entered plain text length %d is not in between 4 to 256",text);
  115.             scanf("%d",&text);
  116.         }while(text<4 || text>256);
  117.     }
  118.    
  119.     /*Inserting the chosen plain text*/
  120.     printf("\nEntered plain text of length is %d " ,text);
  121.     /*scanf ("%s", plain_text);*/
  122.     scanf (" %[^\n]", plain_text);
  123.    
  124.     /*fgets (plain_text,100,stdin);*/
  125.     /*scanf("%s",plain_text);*/
  126.     if(text!=strlen(plain_text)){
  127.         do{
  128.             printf("\n***ERROR!*** Entered Plain Text length is %d it must be %d,",strlen(plain_text),text);
  129.             //scanf ("%s", plain_text);
  130.             scanf (" %[^\n]", plain_text);
  131.         }while(text!=strlen(plain_text));
  132.     }
  133.    
  134.  
  135.    
  136.     strcpy(temp,plain_text);
  137.     clen=strlen(cipher);
  138.    
  139.    
  140.     /*Performing the encryption position N to target value N+1*/
  141.     for(N=0; N<strlen(plain_text); N++){
  142.         if(temp[0]==cipher[N]){
  143.             plain_text[N]=cipher[N+1];
  144.         }
  145.     }
  146.    
  147.     printf("\nStep 1 Substitute %c with %c",cipher[0],cipher[1]);
  148.     printf("\n%s",plain_text);
  149.    
  150.    
  151.     /*Performing the encryption position second position of cipher to target value second last*/
  152.     for(P=1; P<clen-1; P++){
  153.         for(N=0; N<strlen(plain_text); N++){
  154.             if(cipher[P]==temp[N]){
  155.                 plain_text[N]=cipher[P+1];
  156.             }
  157.         }
  158.         printf("\nStep %d substitute %c with %c", P+1, cipher[P],cipher[P+1]);
  159.         printf("\n%s",plain_text);
  160.     }
  161.  
  162.  
  163.     /*Increasing N by one and Repeating all steps till the End of cipher key pointer*/
  164.     for(N=0; N<strlen(plain_text); N++){   
  165.         if(cipher[clen-1]==temp[N]){
  166.             plain_text[N]=cipher[0];
  167.         }
  168.     }
  169.        
  170.     printf("\nStep %d Substitute %c with %c",clen,cipher[clen-1],cipher[0]);
  171.     printf("\n%s",plain_text)
  172.    
  173.  
  174.     return 0;
  175. }