<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2.                                            Pseudo Code
  3.                                            
  4. Get cypher characters count
  5. Get cypher characters
  6. Get plain text characters count
  7. Get plain text characters
  8.                                            
  9. Check that the max amount of the cypher characters is 16
  10. Check that the min amount of the cypher characters is 2
  11. Check that the max amount of the plaintext characters is 256
  12. Check taht the min amount of the plaintext characters is 4
  13.  
  14. Check that the characters in the cypher key are lower case
  15. Check that the characters in the plaintext are lower case
  16.  
  17. Check that the characters in the cypher key only contain letters
  18. Check that the charcaters in the plaintext only contain letters and spaces
  19.  
  20. Check that the cypherkey does not contain duplicate characters
  21.  
  22. Input values of the cypher key into the cypher array
  23. Input values of the plaintext into the plaintext array
  24. Create a temporary plaintext array
  25.  
  26. While the number of characters in the cypherkey is less than the cypherkey number,
  27.    While the number of characters in the plaint text is less than the plaintext number,
  28.       Swap target value with substitute value
  29.       Assign the original plaintext array with the substitute array
  30.       Move one up the cypher key
  31.       Print step number and new plainttext array
  32.    Print final step number and final plaintext array
  33.  
  34.  
  35. */
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. #include <stdio.h>
  46.  
  47. int main( void )
  48. {
  49.    char cypherkey[16]={};
  50.    char text[255]={};
  51.    int swapletter[255]={0};
  52.    int cypherkeynumber;
  53.    int plaintextnumber;
  54.    int ck; /* Cypherkey variable */
  55.    int pt; /* Plaintext variable */
  56.    char fv; /* False variable to remove the enter from being read*/
  57.    int iv; /* Independent variable */
  58.    int sv; /* Secondary variable */
  59.    int tv; /* Third variable */
  60.    sv=0;
  61.    tv=0;
  62.    
  63.    scanf("%d", &cypherkeynumber);
  64.    
  65.    /* Cypherkey length check */
  66.    
  67.    if (cypherkeynumber>16)
  68.    {
  69.    printf("\n Cypher key is too large, can only be 16 characters long.");
  70.    return;
  71.    }
  72.    if (cypherkeynumber<2)
  73.    {
  74.    printf("\n Cypher key is too small, can only be 2 characters short.");
  75.    return;
  76.    }
  77.    
  78.     scanf("%c",&fv); /* False variable to stop the return carriage being read as a character */
  79.    
  80.    /* Cypherkey scan in and character check */
  81.    
  82.    for (ck=0; ck<cypherkeynumber; ck++)
  83.    {
  84.    scanf("%c",&cypherkey[ck]);
  85.    iv = cypherkey[ck];
  86.    tv=0;
  87.    if (cypherkey[ck]>96)
  88.    {
  89.    if (cypherkey[ck]<123)
  90.    {
  91.   }
  92.   else
  93.   {
  94.   printf("\n In cypherkey: Character: %c is not allowed, only lower case letters from a-z are available.", iv);
  95.   return;
  96.   }
  97.   }
  98.   else
  99.   {
  100.   printf("\n In cypherkey: Character: %c is not allowed, only lower case letters from a-z are available.", iv);
  101.   return;
  102.   }
  103.  
  104.   /* Checks cypherkey for duplicate characters */
  105.  
  106.   for (sv=0; sv<cypherkeynumber; sv++)
  107.   {
  108.   if ( iv == cypherkey[sv])
  109.   {
  110.   tv++;
  111.   if (tv == 2)
  112.   {
  113.   printf("Cypherkey cannot contain duplicate letters: %c is put twice.", cypherkey[sv]);
  114.   return;
  115.   }
  116.   }
  117.   }
  118.   }
  119.  
  120.   /* Plain text length check */
  121.  
  122.    scanf("%d", &plaintextnumber);
  123.    
  124.    if (plaintextnumber>256)
  125.    {
  126.    printf("\n Plain text length is too long, can only be 256 characters long.");
  127.    return;
  128.    }
  129.    
  130.    if (plaintextnumber<4)
  131.    {
  132.    printf("\n Plain text length is too short, can only be 4 characters short.");
  133.    return;
  134.    }
  135.    
  136.  
  137.    scanf("%c",&fv); /* false variable */
  138.    
  139.    /* Plain text character check */
  140.    
  141.    for (pt=0; pt<plaintextnumber; pt++)
  142.    {
  143.    scanf("%c",&text[pt]);
  144.    
  145.    if (text[pt]!=32)
  146.    {
  147.    if (text[pt]>96)
  148.    {
  149.    if (text[pt]<123)
  150.    {
  151.   }
  152.   else
  153.   {
  154.   printf("\n In plaintext: Character: %c is not allowed, only lower case letters from a-z and spaces are available.", text[pt]);
  155.   return;
  156.   }
  157.   }
  158.   else
  159.   {
  160.   printf("\n In plaintext: Character: %c is not allowed, only lower case letters from a-z and spaces are available.", text[pt]);
  161.   return;
  162.   }
  163.   }
  164. }
  165.  
  166.    /* Cypherkey array and plaintext array swap */
  167.  
  168.    for (ck=0; ck<cypherkeynumber; ck++)
  169.    {
  170.    for (pt=0; pt<plaintextnumber; pt++)
  171.    {
  172.    if (swapletter[pt]==0)
  173.    {
  174.    if (ck==cypherkeynumber-1)
  175.    {
  176.    if (text[pt]==cypherkey[ck])
  177.    {
  178.    text[pt]=cypherkey[0];
  179.    swapletter[pt]=1;
  180.    }
  181.    }
  182.    else
  183.    {
  184.    if (text[pt]==cypherkey[ck])
  185.    {
  186.    text[pt]=cypherkey[ck+1];
  187.    swapletter[pt]=1;
  188.    }
  189.    }
  190.    }
  191.    }
  192.    if (ck==cypherkeynumber-1)
  193.    {
  194.    printf("\nStep %d substitute %c with %c\n", (ck+1), cypherkey[ck], cypherkey[0]); /* Last step */
  195.    }
  196.    else
  197.    {
  198.    printf("\nStep %d substitute %c with %c \n", (ck+1), cypherkey[ck], cypherkey[ck+1]); /* First steps */
  199.    }
  200.    for(iv=0; iv<plaintextnumber; iv++)
  201.    {
  202.    printf("%c",text[iv]); /* new plain text output */
  203.   }
  204.    }
  205.  
  206.    
  207.  
  208.    
  209.  
  210.  
  211. }