<mosaic.cnfolio.com>
PROGRAM
  1. /* psuedo code
  2. Start:
  3.       Enter the values for the cypher key between 2 - 16
  4.          if the values are above or below the threshold then the program will show an error message
  5.          if the values are within the states thresholds then the program will jump
  6.       after it takes the actual cypher key
  7.          if the cipher key is not equal to stringlength then the program would promt an error message
  8.          if the cypher key is equal it would jump to the next segment
  9.       the program would ask for the length of the text which has to be within the length of 4 - 256
  10.          if the text is above or below the sugested values then the program would show an error message
  11.          if the text is within the range then it would jump to then next segment
  12.       the program will now take the actual text
  13.          the program will take the cypherkey text and substitute it with the letter on the text which was inputted
  14.          this would be displayed
  15. */
  16. #include <stdio.h>
  17. #define MAX_SIZE 16
  18.  
  19. int main()
  20.    {
  21.    int a,b,N,M,e,charlen;
  22.    //these are all of the interger variables
  23.    char cipher_key[MAX_SIZE];
  24.    //these are all of the character variables
  25.    char text[256], temp1[256],temp2[16][256];
  26.    
  27.    printf("Please enter values between 2 - 16: ");
  28.    scanf("%d",&a);
  29.    
  30.    if(a<2 || a>16){
  31.    //this is a statement which checks if the value entered is lower than 2 to greater than 16. If this is true then the statement below will be shown
  32.       do{
  33.          printf("\nThe value %d is not between 2 - 16, please enter again: ",a);
  34.          scanf("%d",&a);
  35.       }while(a<2 || a>16);
  36.       //if the value enteres is between 2 to 16 then this jumps to another statement
  37.    }
  38.    printf("\nEnter the value of %d :",a);
  39.    scanf("%s",cipher_key);
  40.    if(a!=strlen(cipher_key)){
  41.    //when the value entered is equal to the length of the character then the text below will be printed
  42.       do{
  43.          printf("\Entered value is %d, and it has to be %d. Please enter again:",strlen(cipher_key),a);
  44.          scanf("%s",cipher_key);
  45.       }while(a!=strlen(cipher_key));
  46.    }
  47.    printf("\nEnter length of text between 4 - 256: ");
  48.    scanf("%d",&b);
  49.    
  50.    if(b<4 || b>256){
  51.    //this is a statement to see if the value entered is between 4 to 256. if the value is above or below the threshold then the text below will be printed
  52.       do{
  53.          printf("\nEntered length %d is not between 4 - 256, Please try again: ",b);
  54.          scanf("%d",&b);
  55.       }while(b<4 || b>256);
  56.       // if the value entered it between 4 to 256, then the program would jump to the other segment.
  57.    }
  58.    printf("\nEnter text of length %d:",b);
  59.    scanf(" %[^\n]",text);
  60.    
  61.    if(b!=strlen(text)){
  62.    //when the value entered is = to the length of the text then the text below will be printed
  63.       do{
  64.          printf("\nEntered text of length is %d it has to be %d, Please try again: ",strlen(text),b);
  65.          scanf(" %[^\n]",text);
  66.       }while(b!=strlen(text));
  67.    }
  68.  
  69.    strcpy(temp1,text); //Copies the string and then returns the length of the string
  70.    charlen=strlen(cipher_key); //gets the length of the string
  71.    
  72.  
  73.    for(N=0; N<strlen(text); N++){ // if the position of N is 0 the get the length of the text
  74.       if(temp1[0]==cipher_key[N]){   //checks if the string vlaue and the position value is the same
  75.          text[N]=cipher_key[N+1];   // for true condition encrypts the text
  76.       }
  77.    }
  78.    
  79.    printf("\nStep 1 Substitute %c with %c",cipher_key[0],cipher_key[1]);
  80.    printf("\n%s",text);
  81.    //this would be the first substitute where the letter corresponding with the cypherkey is substituted
  82.    
  83.  //creating a loop to irerate over all the item in the collection of the object whihc is returned one at a time
  84.    for(M=1; M<charlen-1; M++){             
  85.       for(N=0; N<strlen(text); N++){
  86.          if(cipher_key[M]==temp1[N]){
  87.             text[N]=cipher_key[M+1];
  88.            
  89.       }
  90.    }
  91.    printf("\nStep %d substitute %c with %c", M+1, cipher_key[M], cipher_key[M+1]); //sends the substitution value
  92.    printf("\n%s",text); //sends the formated output
  93.    }
  94.    //this is the next substituation where the next substuation happens
  95.  
  96.    for(N=0; N<strlen(text); N++){
  97.       if(cipher_key[charlen-1]==temp1[N]){
  98.          text[N]=cipher_key[0];
  99.       }
  100.    }
  101.    
  102.    printf("\nStep %d Substitute %c with %c", charlen,cipher_key[charlen-1],cipher_key[0]);
  103.    printf("\n%s",text);
  104.    //this displays the final result after substuation
  105.    
  106.    return 0; //returns the value of 0
  107. }