<mosaic.cnfolio.com>
PROGRAM
  1. /* PSEUDO CODE
  2. START
  3.  
  4. read first line of input make it equal ro RE
  5.  
  6. if RE is not a number 2 - 16
  7.  
  8.   Show a message saying " Input a valid number for the cipher key 2 - 16 "
  9.   End program
  10.  
  11. End IF
  12.  
  13. Make a loop RE amounts of time
  14.  
  15. Read next input and make it equal to an integer array of 15  called KEY
  16.  
  17.   IF KEY hasnt got a lower case letter between a-z
  18.  
  19.   show a message "Please insert lower case letters only"
  20.     END PROGRAM
  21.    
  22.   END IF
  23.  
  24. read next character and make it equal to integer called RE2
  25.  
  26. IF RE2 is not a number 4 - 256
  27.  
  28.   Show a message saying " Input a valid number for the amount of letter of the plain text. "
  29.   End program
  30.  
  31. End IF
  32.  
  33. Make a loop RE2 amounts of time
  34.  
  35. Read next input and make it equal to an integer array of 255  called TEXT
  36.  
  37.   IF TEXT hasnt got a lower case letter between a-z
  38.  
  39.   show a message "Please insert lower case letters only"
  40.     END PROGRAM
  41.    
  42.   END IF
  43.  
  44.   IF the first letter of the array KEY is in the TEXT array
  45.  
  46.    show message " change (replace with second letter in the key) with (replace with letter thats the same in both arrays)
  47.    then change that letter n the TEXT array with the second letter of the array KEY
  48.  
  49.   END IF
  50.  
  51.    IF key letter repeats
  52.  
  53.    show message saying cannot have same letters in the key
  54.  
  55.   END IF
  56.  
  57. if the first letter in th ekey is in the text array chnage it with the second
  58. if it goes to the end of the key array switch last letter with the first
  59. show the key array
  60. */
  61. #include <stdio.h>
  62. #define onlyletters1  97   /* defining parameter for to compare in the ascii table lettera*/
  63. #define onlyletters2  122  /* defining parameter for to compare in the ascii table letterz*/   
  64. #define space         32   /* defining parameter for to compare in the ascii table space*/
  65.  
  66.  
  67. void main()
  68. {
  69.   /* naming variables*/
  70.   int RE, RE1, i, j, h, temp;
  71.   char key[16] , text[255], text2[255];
  72.   /*start of the input scanning */ 
  73.   scanf("%d\n", &RE);
  74.   if (RE < 2 || RE >= 17)
  75.   {
  76.     printf("Number of letters for the key must be 2-16");
  77.     return;
  78.   } 
  79.   for (i = 0; i < RE; i++)
  80.   {
  81.     scanf("%c", &key[i]);/* reads letters of the key*/
  82.    
  83.     if (key[i] < onlyletters1 || key[i] > onlyletters2)/*only allows the key to have letters from a z*/
  84.     {
  85.       printf("Please insert letters from a - z only, no spaces allowed");return;     
  86.      
  87.     }
  88.    
  89.    
  90.   }
  91.   /*this part reads the number for letters of the input*/
  92.   scanf("\n%d\n", &RE1);
  93.   if (RE1 < 4 || RE1 >= 256)
  94.   {
  95.     printf("Number of letters for the text must be 4-256");
  96.     return;
  97.   }
  98.   for (i = 0; i < RE1; i++)
  99.   {
  100.     scanf("%c", &text[i]);/* reads text*/
  101.     text2[i] = text[i];
  102.     if ((text[i] < onlyletters1 || text[i] > onlyletters2) && text[i] != space) /*only allows the key to have letters from a z + space*/
  103.     {
  104.       printf("Please insert letters from a - z only, paces allowed");
  105.       return;
  106.     }
  107.   }
  108.   /*checking that the letter dont repet in the key*/
  109.   for (i = 0; i < RE; i++)
  110.   {
  111.     for (j = 0; j < RE; j++)
  112.     {
  113.       if (key[i] == key[j] && i != j)
  114.       {
  115.         printf("Please do not repeat letters in the key");
  116.         return;
  117.       }
  118.     }
  119.   }
  120.  
  121.   /* main program */
  122.   for(i = 0; i < RE; i++)
  123.   {
  124.     /*this part makes it so that when it gets to the end of the key it uses the first letter of the key*/
  125.     if (i == (RE-1))
  126.     {
  127.       h=0;
  128.     }
  129.     else {h= i + 1;}/*this part makes it so that it swaps letters in the right order*/
  130.     printf("\n");
  131.     printf("Step %d substitute %c with %c", i+1 ,key[i],key[h]);
  132.     printf("\n");
  133.     for (j = 0; j < RE1; j++)
  134.     {
  135.      
  136.       if(text[j] == key[i])
  137.       {
  138.         text2[j] = key[h];
  139.       }
  140.      
  141.       printf("%c",text2[j]);
  142.     }
  143.    
  144.   }
  145.  
  146. }