<mosaic.cnfolio.com>
PROGRAM
  1. //------------------------------------PSUEDO-CODE-----------------------------//
  2. /*
  3. Start main programme
  4.  
  5. initialize Variables
  6.  
  7. scan from the i/o terminal the length of the cipher text and assign to variable "ciphersize"
  8. scan from the i/o terminal the string to be assigned to array "cipher"
  9. scan from the i/o terminal the length of the plaintext and assign to variable "plaintextsize"
  10. i/o retrieves string from stream input and stores it to array "plaintext"
  11.  
  12. n is set to the integer value 0 (first character of "cipher" array)
  13.  
  14. while loop with condition n less than "ciphersize" is entered.
  15. for integer j=0 (first position of "plaintext") to the last position of the "plaintext" text
  16.     if the first position of the "cipher" array is the same as the j'th position of the "plaintext" array
  17.         if  integer n is less than "ciphersize - 1"
  18.         end if
  19.         store character n+1 to variable "memory"
  20.         store character n+1 to "encrypt" array
  21.         store character "memory" to n+1
  22.         print the n'th step and what swapped with what (n swapped with n+1) n+1 overwrites j when it equals n, show "encrypted" array
  23.         increment integer n
  24.  
  25.         else if integer n is equal to "ciphersize-1"
  26.         store character n=0 to variable "memory"
  27.         store character n=0 to "encrypt" array
  28.         store character "memory" to n=0
  29.         print the n'th step and what swapped with what (n swapped with n=0) n=0 overwrites j when it equals n, show "encrypted" array
  30.         increment integer n
  31.         end else if
  32.     end if
  33. end for
  34.  
  35.     if "cipher" array at position n does not equal the j'th position of the "plaintext" array
  36.         if  integer n is less than "ciphersize - 1"
  37.         print the n'th step and what it supposedly swapped with what (n did not swap with n+1) n+1  does not overwrites j, show unchanged "encrypted" array
  38.         end if
  39.         else if integer n is equal to "ciphersize-1"
  40.         print the n'th step and what supposedly swapped with what (n did not swap with n=0) n=0 does not overwrites j, show unchanged "encrypted" array
  41.         end else if
  42.         increment integer n
  43.     end if
  44. loop back to while if n is less than "ciphersize" if n equals "ciphersize" move out of loop
  45.  
  46. return 0 to end programme
  47.  
  48. */
  49.  
  50.  
  51. #include <stdio.h>
  52. #include <stdlib.h>
  53. #include <string.h>
  54.  
  55. /*------------------------------------------------------- Initialization of variables -----------------------------------------------------*/
  56.  
  57. int main ()
  58. {
  59. char cipher[16];                            /*initializing character array*/
  60. char plaintext[255];                                   /*initializing character array*/
  61. char encrypted[255] = {"hello world"};        /*initializing character array*/
  62. int i,j,n,memory,ciphersize,plaintextsize;            /*initializing variables as integers*/
  63.  
  64. /*------------------------------------------------------------ Taking in the Data ----------------------------------------------------------*/
  65.  
  66. {scanf("%d\n", &ciphersize);}        /*scans the size of the input and stores it to memory*/
  67.     scanf("%s", &cipher);                              /*scans a string and assignis it to the cipher*/
  68. {scanf("%d\n", &plaintextsize);}       /*scans the size of the input and stores it to memory*/
  69.     gets(plaintext);                                       /*retreive text with white space/*
  70.  
  71.  
  72. /*-------------------------------------------------- Forced loop to satisfity all conditions -----------------------------------------------*/
  73.  
  74. n=0;
  75. while(n<ciphersize){
  76.  
  77.    for(j=0;j<plaintextsize;j++){
  78.    
  79.       if(cipher[n] == plaintext[j]){
  80.        
  81.          if(n<ciphersize-1)  {
  82.            
  83.             memory          =   cipher[n+1];
  84.             encrypted[j]    =   memory;
  85.             cipher[n+1]     =   memory;
  86.                
  87.             printf("step \"%d\" substitute \"%c\" for \"%c\"\n \"%s\"\n", n+1,cipher[n],cipher[n+1],encrypted );
  88.             n++;               
  89. }
  90.                                            
  91.          else if(n==ciphersize-1){
  92.            
  93.             memory         =    cipher[0];
  94.             encrypted[j]   =    memory;
  95.             cipher[0]      =    memory;
  96.                
  97.             printf("step \"%d\" substitute \"%c\" for \"%c\"\n \"%s\"\n", n+1,cipher[n],cipher[0],encrypted );
  98.             n++;
  99. }}}
  100.  
  101.          if (cipher[n] != plaintext[j]){
  102.        
  103.             if(n<ciphersize-1){
  104.            
  105.                printf("step \"%d\" substitute \"%c\" for \"%c\"\n \"%s\"\n", n+1,cipher[n],cipher[n+1],encrypted );
  106.                }
  107.            
  108.             else if (n==ciphersize-1){
  109.            
  110.                printf("step \"%d\" substitute \"%c\" for \"%c\"\n \"%s\"\n", n+1,cipher[n],cipher[0],encrypted );
  111.                n++;
  112. }
  113. }}
  114.  
  115.  
  116. //-----------------------------------------------END-PROGRAMME---------------------------------------------------------------//
  117.    
  118.    
  119.    return 0;
  120. }