<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. ------------------------------------------------------------*Program plan paremter*--------------------------------------------------------------
  3. cipher string "trance"
  4. program inputs any character between range 4-256 chracters
  5. create detection for text that is greater than 256 or less than 4
  6. create detection for any character that is not lowercase a-z
  7. N tracks position
  8. position N determines what character in the cipher key is being used
  9. the target value is the position where N is located
  10. The character found at the position N+1 in the cipher key is the substitution value
  11.  
  12.  
  13. ------------------------------------------------------------*Program Pseudo code*----------------------------------------------------------------
  14. create a suitable cypher string, store a s a character string.
  15. user input plain text
  16. if text is not lower case from a-z print input error 001
  17. error 001= input characters must be lowercase letters a-z no punctuation or sysmbols
  18. if input characters less than 4 print input error 002
  19. error 002= iput chracters must be between the range of 4-256 characters to be encrypted
  20. when N=1 the cipher is at the starting position "t"
  21. the next position is: target value+1=substitution value
  22. When the cipher string is at the last value of the cipher string the substitution value is the first character of the cipher string
  23.  
  24. e.g. function;
  25. trance
  26. apples
  27.  
  28. Step 1 substitute t with r
  29. apples
  30. Step 2 substitute r with a
  31. apples
  32. Step 3 substitute a with n
  33. npples
  34. Step 4 substitute n with c
  35. npples
  36. Step 5 substitute c with e
  37. npples
  38. Step 6 substitute e with t
  39. npplts
  40.  
  41. e.g.code implementation;
  42.  
  43. create cipher string (trance) 6 values.
  44. scanf to iput string
  45. store text to be incrypted in array with value assignment
  46. if value array is not a-z lowercase return error
  47. if value array is not 4-256 characters return error
  48. when condition is met, excecute cipher algorithm.
  49. cipher algorithm:
  50. 1.substitute 'target value_1' with 'substitution value_1'
  51. 2.find all values in text with 'target value_1' value and replace with 'substitution value_1' value
  52. 2.let substitution value_1= target value_2
  53. 3.substitute 'target value_x' with 'substitution value_x'
  54. 4.substitution value_x= target value_x+1
  55. 5.when x=6, appply condition if x=6, next term x=1
  56.  
  57. iputs;
  58. print cipher keys length
  59. print cipher key text
  60. print 'text to be encoded' length
  61. print 'text to be encoded' text
  62. outputs;
  63. display each substitution phase
  64. print the target value for each phase
  65. print the substitution value for each phase
  66. print the encrypted text at each phase.
  67.  
  68.  
  69. ------------------------------------------------------------*Main program*-----------------------------------------------------------------------
  70. */
  71. #include <stdio.h>
  72.  
  73. int main()
  74. {
  75.  
  76. char cipher_key []="trance", y;
  77. /* Creating a charcter array to store the cipher key, in each position in the array there is a assigned character value.
  78. This makes up the cipher key*/
  79.  
  80. char encoding_text [257], x;
  81. /* Creating a charcter array to store the inputy plain text in which can be inputyed by the user.
  82. As the length of text is not defined yet, the array size is intentionally left blanked. The last character is the NULL character which makes the array lenth 256+1*/
  83. int running_value;
  84.  
  85. printf("THE PROGRAM INPUTS\n----------------------------------------------");
  86.  for(y = 0; cipher_key[y] != '\0'; ++y);
  87.  
  88.     printf("\nThe length of the cipher key is %d characters", y);
  89.  
  90.  
  91. printf("\nThe cipher string is: %s", cipher_key);
  92.  
  93.  
  94. printf("\nEnter your text to encode:");
  95. scanf("%s", encoding_text);
  96.  
  97.     for(x = 0; encoding_text[x] != '\0'; ++x);
  98.  
  99.     printf("The length of encoding_text string has %d characters", x);
  100.  
  101.  
  102.  
  103. if (x>256,x<4)
  104. {
  105. printf("\nError01-02:\nYour entered plain text had greater than 256 characters or less than 4 characters, or you included a space between your text. Please try again");
  106. scanf("%s", encoding_text);
  107. }
  108.  
  109.  
  110. printf("\nThe text you entered was: %s\n", encoding_text);
  111.  
  112.  
  113. printf("THE PROGRAM OUTPUTS\n----------------------------------------------");
  114.  
  115. printf("\nTarget value is (%c)", cipher_key[0]);
  116. printf("\nSubstitution value is (%c)", cipher_key[1]);
  117.  
  118.  
  119. while(encoding_text[running_value] != '\0')
  120. {
  121.     if(encoding_text[running_value] == cipher_key[0])
  122.      {
  123.        encoding_text[running_value] = cipher_key[1];
  124.      }
  125. running_value++;
  126. }
  127.     printf("\nThe new encryted text is: %s\n", encoding_text);
  128.     printf("This is the first phase of the encryption");
  129.    
  130.  
  131. printf("\nThe second phase is being performed below;");
  132.  
  133. printf("\nTarget value is (%c)", cipher_key[1]);
  134. printf("\nSubstitution value is (%c)", cipher_key[2]);
  135.  
  136.  
  137. while(encoding_text[running_value] != '\0')
  138. {
  139.     if(encoding_text[running_value] == cipher_key[1])
  140.      {
  141.        encoding_text[running_value] = cipher_key[2];
  142.      }
  143. running_value++;
  144. }
  145.     printf("\nThe new encryted text is: %s\n", encoding_text);
  146.  
  147.  
  148. printf("The third phase is being performed below;");
  149.  
  150. printf("\nTarget value is (%c)", cipher_key[2]);
  151. printf("\nSubstitution value is (%c)", cipher_key[3]);
  152.  
  153.  
  154. while(encoding_text[running_value] != '\0')
  155. {
  156.     if(encoding_text[running_value] == cipher_key[2])
  157.      {
  158.        encoding_text[running_value] = cipher_key[3];
  159.      }
  160. running_value++;
  161. }
  162.     printf("\nThe new encryted text is: %s\n", encoding_text);
  163.  
  164.  
  165. printf("The fourth phase is being performed below;");
  166.  
  167. printf("\nTarget value is (%c)", cipher_key[3]);
  168. printf("\nSubstitution value is (%c)", cipher_key[4]);
  169.  
  170.  
  171. while(encoding_text[running_value] != '\0')
  172. {
  173.     if(encoding_text[running_value] == cipher_key[3])
  174.      {
  175.        encoding_text[running_value] = cipher_key[4];
  176.      }
  177. running_value++;
  178. }
  179.     printf("\nThe new encryted text is: %s\n", encoding_text);
  180.  
  181. printf("The fifth phase is being performed below;");
  182.  
  183. printf("\nTarget value is (%c)", cipher_key[4]);
  184. printf("\nSubstitution value is (%c)", cipher_key[5]);
  185.  
  186.  
  187. while(encoding_text[running_value] != '\0')
  188. {
  189.     if(encoding_text[running_value] == cipher_key[4])
  190.      {
  191.        encoding_text[running_value] = cipher_key[5];
  192.      }
  193. running_value++;
  194. }
  195.     printf("\nThe new encryted text is: %s\n", encoding_text);
  196.    
  197.  
  198. printf("The sixth phase is being performed below;");
  199.  
  200. printf("\nTarget value is (%c)", cipher_key[5]);
  201. printf("\nSubstitution value is (%c)", cipher_key[6]);
  202.  
  203.  
  204. while(encoding_text[running_value] != '\0')
  205. {
  206.     if(encoding_text[running_value] == cipher_key[5])
  207.      {
  208.        encoding_text[running_value] = cipher_key[6];
  209.      }
  210. running_value++;
  211. }
  212.     printf("\nThe new encryted text is: %s\n", encoding_text);
  213.    
  214. printf("The seventh phase is being performed below;");
  215.  
  216. printf("\nTarget value is (%c)", cipher_key[6]);
  217. printf("\nSubstitution value is (%c)", cipher_key[0]);
  218.  
  219.  
  220. while(encoding_text[running_value] != '\0')
  221. {
  222.     if(encoding_text[running_value] == cipher_key[6])
  223.      {
  224.        encoding_text[running_value] = cipher_key[0];
  225.      }
  226. running_value++;
  227. }
  228.     printf("\nThe new encryted text is: %s\n", encoding_text);
  229.    
  230. return 0;
  231. }