<mosaic.cnfolio.com>
PROGRAM
  1. /* --------------------------------------------------------------------------------- */
  2. /* --------------------------------  PSEUDOCODE  ----------------------------------- */
  3. /* --------------------------------------------------------------------------------- */
  4.  
  5. /*
  6.  
  7. Input lenKey and Key
  8. Append the first sysmbol of the key to the end of string key
  9. Input lenText, text, initialise flags by 0
  10. For each symbol in key
  11.     for each symbol in text
  12.         if key symbol is equal text symbol was not replaced earlier
  13.            replace text symbol to the next key symbol
  14.                set current flags item to 1
  15.         print current step and current substitute
  16.         print changed text
  17.  
  18. */
  19.  
  20. /* --------------------------------------------------------------------------------- */
  21. /* --------------------------  BEGINNING OF MAIN PROGRAM  -------------------------- */
  22. /* --------------------------------------------------------------------------------- */
  23.  
  24. #include <stdio.h>
  25.  
  26. /*Declare Variables */
  27.  
  28. int main()
  29.     {
  30.     int lenKey, lenText,i,j,flags[256];
  31.     char key[17], text[256],c;
  32.    
  33.     //input lenKey and key
  34.     scanf("%d", &lenKey);
  35.     getchar();
  36.    
  37.     //prompts the user to end the cipher key
  38.     i=0;
  39.     while((c = getchar()) != '\n' && c != EOF)
  40.         key[i++]=c;
  41.    
  42.     //append the first symbol of the key to the end of string key
  43.     key[i++]=key[0];
  44.    
  45.     //set end of string
  46.     key[i]='\0';
  47.    
  48.     //input lenText
  49.     scanf("%d", &lenText);
  50.     getchar();
  51.    
  52.     //prompts the user to enter the plain text to be encrypted
  53.     i=0;
  54.    
  55.     //input text
  56.     while((c = getchar()) != '\n' && c != EOF)
  57.         {
  58.         text[i]=c;
  59.          //initialize flags by 0
  60.         flags[i++]=0;
  61.         }
  62.     //set end of string
  63.     text[i]='\0';
  64.    
  65.     //for each symbol in key
  66.     for(i=0;i<lenKey;i++){
  67.         //for each symbol in text
  68.         for(j=0;j<lenText;j++)
  69.             //if key symbol is equal text symbol and text symbol was not replaced earlier
  70.             if(text[j]==key[i] && flags[j]==0)
  71.                 {
  72.                 //replace text symbol to the next key symbol
  73.                 text[j]=key[i+1];
  74.                 //set current flags item to 1 (was replaced)
  75.                 flags[j]=1;
  76.                 }
  77.        
  78.     //print currrent step and urrent substitute and changed text
  79.     printf("Step %d substitute %c with %c\n%s\n", i+1,key[i],key[i+1],text);
  80.        
  81.     }
  82.    
  83.     return 0;
  84. }