<mosaic.cnfolio.com>
PROGRAM
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. /*=============Pseudo Code========*/
  4. /*Input:
  5. Get the input size of cipher key
  6. Scanf
  7.  
  8. Get the input values of the cipher key
  9. Scanf
  10. Cipher must be 2to16 characters in length
  11.    if cipher <2 or >16
  12.     error, return end program
  13.    
  14. Get the length of the input text
  15. Scanf
  16. Input text must be 4 to 256 characters in length
  17.   if text <4 or >256
  18.     error, return end program
  19.    
  20. Get the input text tiself
  21. Scanf
  22.  
  23. */
  24.  
  25. /*Encryption Process:
  26.  
  27. */
  28.  
  29. /*=============Main fucntion=========*/
  30. int main(void){
  31.  
  32.    char ciphertext[256], ch; //USed to the text to encrypt
  33.    int  lengthcipher; //length of the cipher key
  34.    char textput[256];
  35.    int  lengthtext; //Length of the text to be encrypted
  36.    char cipherkey[16]; //Words used to replace in cipher
  37.    char hold[256]; //used to hold cipher text temporary
  38.    int length;
  39.    int N;
  40.    int i, key;
  41.    
  42. // Input Starts with along with Input error checking
  43. {
  44.   printf("Insert Cipher lenght: ");
  45.   scanf("%d", &lengthcipher); //Scans iput for Cipher lenght
  46.  
  47. //Error checking for the correct cipher lenght
  48.   if(lengthcipher<2)/*checks if the cipher lenght is under the character limit*/
  49.     {
  50.       printf("Error, lenght must be over 2 characters\n");
  51.       return 0;
  52.       }
  53.    
  54.    if(lengthcipher>16)/*checks if the cipher lenght is over the character limit*/
  55.     {
  56.       printf("Error, lenght must be under 16 characters\n");
  57.       return 0;
  58.       }
  59. //Error check ends
  60.  
  61.   for(length = 0; length <= lengthcipher; length++)
  62.   {
  63.    printf("Insert Cipher Keys: ");
  64.    scanf("%c", &cipherkey[length]); //Scans input for Cipher keys
  65.   }
  66.    printf("Insert Text lenght (including spaces): ");
  67.    scanf("%d", &lengthtext); //Scans iput for Text lenght
  68.  
  69. //Error checking for the correct text lenght   
  70.    if(lengthtext<4)/*checks if the text lenght is under the character limit*/
  71.     {
  72.       printf("Error, text lenght must be over 4 characters\n");
  73.       return 0;
  74.       }
  75.       if(lengthtext>256)/*checks if the tex lenght is over the character limit*/
  76.       {
  77.       printf("Error, text must be under 256 characters\n");
  78.       return 0;
  79.       }
  80. //Error check ends 
  81.  
  82.  for(length = 0; length <= lengthtext; length++)
  83.   {
  84.    printf("Insert Text to Encrypt: ");
  85.    scanf("%c", &ciphertext[length]); //Scans iput for Cipher text
  86.    hold[length] = ciphertext[length];
  87.   }
  88. } 
  89.  
  90.  
  91. /*============Encryption Starts===========*/
  92.  
  93.    for(N = 1; N <= lengthcipher; N++)
  94.   {
  95.   if(N == lengthcipher)
  96.   {
  97.     for(length = 1; length <= lengthtext; length++)
  98.          {
  99.           N=1;
  100.           hold[length] = cipherkey[N];
  101.           }
  102.          
  103.           N=lengthcipher;
  104.            printf("\n Step %d substitute %c with %c\n", N, cipherkey[N],cipherkey[1]);
  105.            for(length=1;length<=lengthtext;length++)
  106.             {
  107.              printf("%c", hold[length]);
  108.             }
  109.         }
  110.     for(length = 1; length <= lengthtext; length++)
  111.     {
  112.     if (count == cipherkey[N])
  113.      {
  114.       switch{
  115.       case '1':
  116.       case '2':
  117.       case '3':
  118.       case '4':
  119.       case '5':
  120.       case '6':
  121.       case '7':
  122.       case '8':
  123.       case '9':
  124.       case '10':
  125.       case '11':
  126.       case '12':
  127.       case '13':
  128.       case '14':
  129.        {
  130.         hold[length] = cipherkey[N + 1];
  131.        }
  132.      }
  133.    }
  134.      printf("\n Step %d substitute %c with %c\n", N, cipherkey[N],cipherkey[N + 1]);
  135.      for(length=1;length<=lengthtext;length++)
  136.       {
  137.        printf("%c", hold[length]);
  138.       }
  139.   }
  140.  
  141. }