<mosaic.cnfolio.com>
PROGRAM
  1. #include<stdio.h>
  2. #include<limits.h>
  3.  
  4. int main()
  5. {
  6.  
  7.     int key_len;    /*Length of Cipher Key*/
  8.     int txt_len;    /*Length of Input Text*/
  9.     int C ;         /*Array Position in Text Message - Starts at 0*/
  10.     int N ;         /*Position in Cipher Key*/
  11.     int A ;     /*Array Position in Cipher Key - Starts at 0* /
  12.     int R ;     /*Position in Key of Replacement Character*/
  13.    
  14.     printf("Enter number for length of cipher key between 2 & 16: ");   /*asks the user for cipher key length*/
  15.     scanf("%d", &key_len);                   /*stores the entered cipher key length*/
  16.  
  17.     char key[key_len];               /*Input cipher key string max length 16*/
  18. /* or char key[16]; */
  19.    
  20.     printf("Enter cipher key text: ");                /*asks the user for the cipher key text*/
  21.     scanf("%s", &key);        /*stores the entered value for the length of the cipher key*/
  22.     printf("Enter number for length of text for encryption between 4 & 256: ");  /*asks the user for text length*/
  23.     scanf("%d", &txt_len);                   /*stores the entered cipher key length*/
  24.  
  25.     char text[txt_len];                   /*Input text string max length 256*/
  26. /* or char text[256]; */
  27.    
  28.     printf("Enter plain text to be encrypted: ");    /*asks the user for the text to be encrypted*/
  29.     scanf("%s", &text);                      /*stores the text for encryption*/
  30.  
  31.  
  32.     N = 1 ;
  33.  
  34.     char repchar;
  35.     while (N <= key_len) ++N;{
  36.     char keychar = key[N-1];
  37.     if (N < key_len){
  38.     repchar = key[N];
  39.        }
  40.     else {
  41.     repchar = key[0];
  42.        }
  43.  
  44.     for(C = 0; text[C] != '\0'; ++C){
  45.         char inchar = text[C];
  46.  
  47.         if(inchar == keychar ){
  48.             text[C] = repchar;       
  49.            
  50.         }
  51.             }
  52.  
  53.    printf("Step  %N  substitute  %keychar  with  %repchar" );
  54.    printf("%text");
  55.                 }
  56.    
  57.     return 0;
  58. }