<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2.                                                          Pseudocode as follows
  3.                      
  4. START
  5. Clear Memory
  6. READ Cipher Key Length
  7. IF Cipher Key is between 2-16 characters long
  8. IF Cipher Key has no capital letters
  9. IF Cipher Key has no duplicated letters
  10. READ Input of Plain Text for Encryption
  11. IF Plaintext is between 4-256 characters long
  12. IF Plaintext contains no Capital Letters
  13. BEGIN Encryption Process
  14. READ Character at Position N to determine target value
  15. READ Character at Position N+1 to determine substitution value
  16. WHILE Encryption Process is taking place
  17. WHILE Values are not within substition value range
  18. IF Characters have not been substituted before
  19. PRINT "A Character has been substituted by B Character"
  20. Substitute all A Characters in B Character
  21. PRINT encrypted string which have used the B Character Cipher Key
  22. END IF
  23. END WHILE
  24. END WHILE
  25. END
  26.  
  27. ================================================================================================
  28. /*
  29.  
  30.                                                    Actual Program Coding Starts here
  31.                  
  32.                  
  33. */
  34.  
  35.                                                          /* Start of Program */
  36.  
  37. #include <stdio.h>
  38. #include <string.h>
  39.  
  40. int
  41. main (void)
  42. {
  43.  
  44.                                                       /* Declaration of Variables */
  45.   int encrypterlength;
  46.   char encrypter[16];
  47.   char plaintext[256];
  48.   int plaintextlength;
  49.   int encryptcheck = 0;
  50.   int plaintxtcheck = 0;
  51.   char result;
  52.   int sequence = 0;
  53.   char temporary[256];
  54.   int testing;
  55.   int identifier;
  56.  
  57.  
  58.  
  59.                                              /* Detecting Inputs for the Operation of the Program */
  60.   scanf ("%d", &encrypterlength);
  61.   scanf ("%s", &encrypter);
  62.   scanf ("%d", &plaintextlength);
  63.   scanf (" %[^\n]s", &plaintext);
  64.   scanf ("%[a-z ]", &plaintext);
  65.  
  66.   strcpy (temporary, plaintext);
  67.  
  68.  
  69.  
  70.  
  71.                                                       /* Process of Error Checking */
  72.                                                      
  73.                                                      
  74. /* Error Check to verify that the cipher key is between 2-16 characters long */
  75.   {
  76.     if (encrypterlength < 2)
  77.       {
  78.    printf ("The Cipher must be between 2 to 16 charachters in length");
  79.    return 0;
  80.       }
  81.  
  82.  
  83.  
  84. /* Error Check to verify that Plain Text is between 4-256 characters long */
  85.     {
  86.       if (plaintextlength < 4)
  87.    {
  88.      printf
  89.        ("The length of text must be between 4 to 256 characters in length");
  90.      return 0;
  91.    }
  92.     }
  93.  
  94.  
  95. /* Error check to verify whether or not capital letters are placed in the input */
  96.  
  97. for (plaintxtcheck = 0; plaintxtcheck < plaintextlength; plaintxtcheck++)
  98. {
  99. if (plaintext[plaintxtcheck] >= 'A' && plaintext[plaintxtcheck] <= 'Z')
  100. {
  101. printf ("\n Capital Letters are not accepted in the plain text field - To rectify, change these to lower case letters ");
  102. return 0;
  103. }
  104. }
  105.  
  106. /* Error check to verify whether or not numerical digits are entered in the input */
  107.  
  108. for (plaintxtcheck = 0; plaintxtcheck < plaintextlength; plaintxtcheck++)
  109. {
  110. if (plaintext[plaintxtcheck] >= '0' && plaintext[plaintxtcheck] <= '9')
  111. {
  112. printf ("\n Numbers are not accepted in the plain text field - To rectify, remove these characters ");
  113. return 0;
  114. }
  115. }
  116.  
  117. /* Error Check to verify if there are duplicate characters or not  */
  118.  
  119. for(testing=0; testing <encrypterlength; testing++)
  120. {
  121. for(identifier=testing+1; identifier <encrypterlength+1; identifier++)
  122. {
  123. if (encrypter[testing] == encrypter[testing + 1])
  124. {
  125. printf ("\n Duplicate Character found - To rectify, change this duplicate character");
  126. return 0;
  127. }
  128. }
  129. }
  130.                                                 /* Beginning of Encryption Process */
  131.                                                    
  132.  
  133.     for (encryptcheck = 0; encryptcheck < encrypterlength; encryptcheck++)
  134.       {
  135.    sequence++;
  136.  
  137.  
  138.    for (plaintxtcheck = 0; plaintxtcheck < plaintextlength;
  139.         plaintxtcheck++)
  140.      {
  141.  
  142.  
  143.        if (plaintext[plaintxtcheck] == encrypter[encryptcheck])
  144.          {
  145.       temporary[plaintxtcheck] = encrypter[encryptcheck + 1];
  146.          }
  147.  
  148.        if (encryptcheck == encrypterlength - 1)
  149.         {
  150.          for (plaintxtcheck = 0; plaintxtcheck < plaintextlength;
  151.          plaintxtcheck++)
  152.       {
  153.  
  154.         if (plaintext[plaintxtcheck] == encrypter[encryptcheck])
  155.           {
  156.  
  157.             temporary[plaintxtcheck] = encrypter[0];
  158.  
  159.  
  160.                            /* The Outcome of the Encryption - the string of plain text has now been sucessfully substitued */
  161.                            
  162.                            
  163.  
  164. /* This Prints the Value at Position N - Thereby the TARGET VALUE */
  165.  
  166.             printf ("Stage %d: substitued %c using %c\n", sequence,
  167.                encrypter[encryptcheck], encrypter[0]);
  168.  
  169.             printf ("%s\n", temporary);
  170.             return 0;
  171.           }
  172.       }
  173.      }
  174. }
  175.  
  176.  
  177. /* This prints the value of Position N+1 - Thereby the SUBSTITUTION VALUE */
  178.  
  179.    printf ("Stage %d: substitued %c using %c\n", sequence,
  180.       encrypter[encryptcheck], encrypter[encryptcheck + 1]);
  181.    printf ("%s\n", temporary);
  182.       }
  183.   }
  184. }
  185.  
  186.  
  187.  
  188.                                                                /* End of Program */