<mosaic.cnfolio.com>
PROGRAM
  1. /*>>>>---------------------------PSUDO CODE----------------------------<<<<.
  2.  
  3.  
  4. input number of characters you want to change
  5. input the letters you want to swap
  6. input of how the many letters are in the sentence you wish to change
  7. define letters you want to change
  8. step 1 change the first letter
  9. define it as swapped so it does not swap back
  10. step 2 swap the second letter
  11. define it as swapped
  12. output the the finished sentence in the incripted product
  13. all characters must be in lower case
  14. no character duplicates are allowed.
  15. must be 4<>256 charactors long
  16.  
  17. */
  18.  
  19. #include<stdio.h>
  20.  
  21.  
  22. int main( void )
  23. {
  24.   char cipherkey[16];
  25.   char text[255];
  26.   int letterswap[255] = {0};
  27.   int cipherkeynumber, plaintextnumber,i,j,k,g;
  28.  
  29.   scanf("%d", &cipherkeynumber);
  30.   if (cipherkeynumber>16){
  31.     printf("Cipher key is too large");
  32.   }
  33.   else{
  34.     scanf("%c",&text[0]);
  35.     /* read everything into the array */
  36.     for (i = 0; i < cipherkeynumber; i++)
  37.     {
  38.       scanf("%c", &cipherkey[i]);
  39.      
  40.     }
  41.     scanf("%d", &plaintextnumber);
  42.     if (plaintextnumber>256){
  43.       printf("Plain text is too large");
  44.     }
  45.     else{
  46.      
  47.      
  48.       /* Using false variable to allow the programme to read enter as a space */
  49.       scanf("%c", &text[0]);
  50.       for (i = 0; i < plaintextnumber; i++)
  51.       {
  52.         scanf("%c", &text[i]);
  53.         if (text[i] >= "a" || text[i] <= "a"){
  54.         }
  55.         else{
  56.           printf("character not valid");
  57.         }
  58.       }
  59.       printf("\n");
  60.      
  61.       /*changed array is implemented*/
  62.       for (i = 0; i < cipherkeynumber; i++){
  63.         for (j = 0; j < plaintextnumber; j++){
  64.           if (letterswap[j] == 0){
  65.             if (i == cipherkeynumber - 1){
  66.               if (text[j] == cipherkey[i]){
  67.               text[j] = cipherkey[0];
  68.               letterswap[j] = 1;
  69.             }
  70.             }
  71.             else{
  72.               if (text[j] == cipherkey[i]){
  73.                 text[j] = cipherkey[i+1];
  74.                 letterswap[j] = 1;
  75.               }
  76.             }
  77.           }
  78.         }
  79.       if (i == cipherkeynumber - 1){
  80.         printf("Step %d substitute %c with %c\n", (i+1), cipherkey[i], cipherkey[0]);
  81.       }
  82.       else {
  83.         printf("Step %d substitute %c with %c\n", (i+1), cipherkey[i], cipherkey[i+1]);
  84.       }
  85.       for (k = 0; k < plaintextnumber; k++){
  86.         printf("%c", text[k]);
  87.       }
  88.       printf("\n");
  89.       }
  90.     }
  91.   }
  92.  
  93. }