<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2.   >>>>> ---- ---- ---- ---- ---- ---- ---- ---- pseudo code ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <<<<<
  3.   >>>>> ---- ---- ---- ---- ---- ---- ---- ---- ........... ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <<<<<
  4.  
  5. Start.
  6.        
  7.        
  8.     *declaration of Variables and Arrayes .
  9.    
  10.    
  11.        
  12.     *Generate steps needed to display the out.
  13.    
  14.  
  15.  
  16.     *Get user inputs
  17.        
  18.        
  19.        
  20.      
  21.     *loop through user input and replace with the relevant character.
  22.    
  23.    
  24.       if
  25.        
  26.         incase of substitute, the end of the cipherkey, replace the last character with the first character.
  27.          
  28.          
  29.          
  30.       else
  31.      
  32.      
  33.            Replace it with the next character.                                           
  34.          
  35.          
  36.       if
  37.            the plain text is relavnt character replace it cipherkey characters
  38.            
  39.            
  40.       else if 
  41.            
  42.            
  43.            Replace it with the next Character.
  44.            
  45.            
  46.      
  47.      *Display the steps and the output.
  48.        
  49.        
  50.  
  51.  
  52. END
  53.  
  54. */
  55. /*
  56. >>>> ---- ---- ---- ---- ---- ---- ---- Source Code ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <<<<
  57. >>>> ---- ---- ---- ---- ---- ---- ---- ........... ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <<<<*/   
  58.      
  59.   #include <stdio.h>
  60.   #include <string.h>
  61.  
  62.  
  63.  
  64.    int main()
  65.  
  66. {
  67.  
  68.  
  69. /*
  70.       Declare Varibles and Arrays
  71.       it is important to use meaningful and appropriate names for variables and Arrays */
  72.      
  73.     int  i,j; /*<<<<<<<<<<<<<<<<<<<< Declaration of variables i and j, for loop */
  74.       char keylngth[256];/*<<<<<<<<< Array to store the length of the cipher key */
  75.         char ciphrkeytxt[16];/*<<<<< Array to store the cipher key */
  76.          char substitute [256];/*<<< Array to store the length of the plain text */
  77.            char  plantxt[10];/*<<<<< Array to store the plain text. */
  78.    
  79.      
  80.      
  81.      
  82. /*
  83.      Generate steps needed to display the output */
  84.      for (i=0;i<256;i++){ /*<<<<<<<<   i is smaller then 256, the code will loop*/
  85.               substitute [i]='0';   /* untill reaches 256.after each iteration
  86.                                        of the loop, it increments i by 1 (i++).
  87.                                        so that the loop will stop when it meets the 1 < 256 */
  88. }
  89.  
  90.  
  91.  
  92.  
  93. /*
  94.      Prints or dislay the following message.*/
  95.      printf("The program display the following output:\n");
  96.    
  97.    
  98.    
  99.    
  100. /*
  101.     Gets users inputs*/
  102.      int x;
  103.        gets(plantxt);        /* gets function is used to get user inputs and store in plantxt array*/       
  104.         x=atoi(plantxt);     /* converting the string variables into numerical value*/
  105.          gets(ciphrkeytxt)/* Gets Function is used to get user inputs and store in ciphrkettxt */
  106.                              
  107.      int y;
  108.       gets(plantxt);        /* gets the input from the user and store in the plantext array.*/
  109.      
  110.    
  111.  
  112.  
  113.  
  114. /* 
  115.      loop through the user input and replace the relvent character with cipherkey.*/
  116.      for(j=0;j<x;j++) {     
  117.      
  118.         y=atoi(plantxt);   /* atoi function converts a string into numerical value*/
  119.                            /* gets function gets user inputs and store in the Keylngth array*/
  120.          gets(keylngth);
  121.  
  122.           char char_from=ciphrkeytxt[j];
  123.             char char_to;
  124.    
  125.    
  126.    
  127.    
  128. /*
  129.       Incase of substitue the end of the cipher key replace the last character with first character.*/         
  130.       if (j==x-1)
  131.         char_to=ciphrkeytxt[0];
  132.        
  133.        
  134. /*
  135.      Otherwise replace it with the next character. */
  136.     else
  137.      char_to=ciphrkeytxt[j+1];
  138.           for(i=0;i<y;i++){
  139.          
  140.    
  141. /*
  142.      Replace the plain text relvant characters with the key characters. */
  143.    if (keylngth[i]==ciphrkeytxt[j]&&(j!=x-1)&&(substitute [i]=='0')){
  144.             keylngth[i]=ciphrkeytxt[j+1];
  145.                    substitute [i]='s';
  146.                    
  147. }
  148. /*
  149.      Replace it with the next Character.*/
  150.    else if
  151.       (keylngth[i]==ciphrkeytxt[j]&&(j== x -1)&&(substitute[i]=='0')){
  152.          keylngth[i]=ciphrkeytxt[0];
  153.            substitute [i]='s';
  154. }
  155. }
  156.  
  157.  
  158.  
  159. /*
  160.     Display the steps and the output.*/
  161.    printf("step %d substitute  %c with %c \n",j+1, char_from,char_to);
  162.    printf(" %s\n",keylngth);
  163.  
  164. }
  165.   return 0;
  166.    
  167. }
  168.  
  169. /*
  170. <<<< ---- ---- ---- ---- ---- ---- ---- ----END of the Code--- ---- ---- ---- ---- ---- ---- ---- ---- >>>>> */