<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. Pseudo code:
  3. Input the length of cipher
  4. IF the input for the length of the cipher is not a number
  5. THEN display error
  6. END IF
  7.   IF the length of the cipher is not between 2 to 16
  8.     THEN display error message
  9. END IF       
  10. Input the cipher
  11. If cipher it’s not between 2 to 16 characters
  12. THEN display error message
  13. END IF
  14.   IF cipher it’s not a letter
  15.     THEN display error message
  16. END IF
  17. IF any capital letters are inputted in cipher
  18.     THEN display error message
  19. END IF
  20. Input text length
  21. IF text length it’s not a number
  22. THEN display error message
  23. END IF
  24. IF characters in text length are not between 4 to 256
  25.     THEN display error message
  26. END IF
  27. Input text
  28. IF characters in the text are not letters
  29.      THEN display error
  30. END IF
  31. IF characters in the text are not lower case
  32. THEN display error messages
  33. END IF
  34. IF Errors are found
  35.      THEN display error messages
  36. END IF         
  37. IF Errors are not found
  38.      THEN
  39.         The first character found in the cipher have the target value
  40.         The second character found in the cipher have the substitution value
  41. END IF
  42.    Input the first character which is the target value in the cipher text and match with the characters in the plain text
  43. END IF         
  44. IF the target value in the cipher text found in the text
  45.      THEN
  46.          Substitute the target value found in the text with the substitution value in the cipher text
  47.          Display the step number and the target value with the substituted substation value
  48.          Display the complete encrypted text
  49.          Replicate the steps until the end of the cipher
  50. END IF 
  51. END
  52.  
  53. */
  54. #include <stdio.h>
  55. #include <string.h>
  56. #include <ctype.h>
  57.  
  58. int cipherLength;
  59. int a;
  60. int b;
  61. int c;
  62. int d;
  63. char cipher[16];
  64. int textoLength;
  65. char text1[256];
  66. char text2[256];
  67. char alpha;
  68.  
  69. // main Code //
  70.  
  71. int main(void)
  72. {
  73.  
  74. // inputs & error check //
  75.  
  76.     scanf("%d", &cipherLength); // input the size of the cipher
  77.  
  78.  
  79.     if(scanf("%c", &alpha),isalpha(alpha)){ 
  80.         printf("error, cipher length should be a number\n")// display the error if the input of the cipher is a letter
  81.         return 0;
  82.     }
  83.  
  84.     if((cipherLength < 2) || (cipherLength > 16)){
  85.         printf("error, cipher length should be between 2 to 16\n");
  86.         return 0;
  87.     }
  88.  
  89.     scanf("%s", &cipher);
  90.     for(a = 0; a < cipherLength; a++) {
  91.         if (isdigit(cipher[a])) {
  92.             printf("error, cipher should be only letters\n");
  93.             return 0;
  94.         }
  95.         if (isupper(cipher[a])) {
  96.             printf("error, cipher should be only lower case\n");
  97.             return 0;
  98.         }
  99.     }
  100.  
  101.     scanf("%d", &textoLength);
  102.  
  103.  
  104.     if(scanf("%c", &alpha),isalpha(alpha)){
  105.         printf("error, text length should be a number\n");
  106.         return 0;
  107.     }
  108.  
  109.     if((textoLength < 4) || (textoLength > 256)){
  110.         printf("error, text length should be between 4 to 256\n");
  111.         return 0;
  112.     }
  113.  
  114.  
  115.     for(a = 0; a < textoLength; a++) {
  116.         if (isdigit(text1[a])) {
  117.             printf("error, text should be letters\n");
  118.             return 0;
  119.         }
  120.         if (isupper(text1[a])) {
  121.             printf("error, text should be lower case\n");
  122.             return 0;
  123.         }
  124.     }
  125.     scanf("\n%[^\n]",&text1);
  126.     strncpy(text2, text1, 256);
  127.  
  128. // encryption of the text //
  129.  
  130.     for(b=0; b < cipherLength; b++){
  131.  
  132.         for(d=0; d < textoLength; d++){
  133.  
  134.  
  135.             if(text1[d] == cipher[b]){
  136.  
  137.  
  138.                 text2[d] = cipher[b + 1];
  139.             }
  140.         }
  141.         c= b + 1;
  142.  
  143. //output //
  144.  
  145.         cipher[cipherLength] = cipher[0];
  146.         printf(" \nStep %d substitute %c with %c", c, cipher[b], cipher[b + 1]);
  147.         printf("\n %s", text2);
  148.     }
  149.     return 0;
  150. }