<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2.  
  3. Start the Program
  4.  
  5. Set limits for size of sentence and key lengths
  6. Read first integer as cipher key length
  7. Add such number of following characters to list as cipher key
  8. Read next integer as character count in sentence
  9. Add such number of following characters to list as original sentence
  10.  
  11. Enter loop
  12.  
  13. Set a limit so the loop stops at one less than the cipher key length
  14. Using the first character in the cipher key, sift through the sentence to find an equal character
  15. Switch the character found with the following character in the key
  16. State the step of the encryption completed so far and which character has been replaced by what
  17. Return to beginning of loop, reading the following character in the key as the character to be changed
  18.  
  19. End the Program
  20.  
  21. */
  22.  
  23. #include <stdio.h>
  24.     #define min_size_cipher 2
  25.    #define max_size_cipher 16
  26.    #define min_size_txt 4
  27.    #define max_size_txt 256
  28.        int main(void)
  29.           {
  30.          int keyL;
  31.          int txtL;
  32.          int c;
  33.          int y;
  34.          char key[max_size_cipher];
  35.          char txt[max_size_txt];
  36.          char target[1];
  37.          char substitute[1];
  38.          int loop1;
  39.          int loop2;
  40.  
  41.          scanf ("%d", &keyL);            /*following section scans cipher key length and adds letters to array*/
  42.  
  43.          if (keyL > 16){
  44.              printf("key length should be between 2 and 16");
  45.             }
  46.  
  47.          for (c = 0; c <= keyL; c++)
  48.          {
  49.              scanf ("%c", &key[c]);
  50.  
  51.              printf ("%c", key[c]);
  52.          }
  53.  
  54.          scanf ("%d", &txtL);            /*following section scans text length and adds letters to array*/
  55.  
  56.          if (txtL > 256){
  57.              printf("text length should be between 4 and 256");
  58.             }
  59.  
  60.          scanf ("%[^n]s", &txt);
  61.  
  62.          printf ("\n%s", txt);
  63.          for (loop1 = 0; loop1 < keyL; loop1++)          /*enter loop*/
  64.          {
  65.               (target[1] = key[keyL - (keyL - 1) + loop1]);
  66.              (substitute[1] = key[keyL - (keyL - 2) + loop1]);
  67.  
  68.              if ((keyL - (keyL - 1) + loop1) == keyL)
  69.                  {substitute[1] = key[1];}
  70.                    printf("\ntar = %c sub = %c", target[1], substitute[1]);
  71.  
  72.                   for (loop2 = 0; loop2 < txtL; loop2++)
  73.                   {
  74.                       if (txt[loop2] == target[1])
  75.                          {txt[loop2] = substitute[1];
  76.                          printf ("\n%s", txt);
  77.                         }
  78.  
  79.                    }
  80.  
  81.          }
  82.  
  83. }