<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. Pseudo code:
  3.               START
  4.              
  5. Enter length of cipher key from 2 to 16
  6. The cipher key length must be between 2 to 16
  7. if the cipher key length less than 2 or more than 16
  8. then its Error
  9.  
  10. Taking actual cipher key
  11. Enter the cipher key length
  12. The cipher key needs to be equal to stinglenth
  13. if not
  14. The cipher key length is not between 2 to 16
  15.  
  16. Enter length of plain text from 4 to 256
  17. The plain length needs to be between 4 to 256
  18. if not
  19. The plain length is less than 4 or more than 256
  20.  
  21. Taking actual plain text
  22. Enter plain text length
  23. The plain text length must be equal to stringlenth
  24. if not
  25. The plain text length is not between 4 to 256
  26.  
  27. Performing the encryption position N to target value N+1
  28.  
  29.  
  30. Performing the encryption position second position of cipher to targer value second last
  31.  
  32.  
  33. End of cipher key pointer
  34.  
  35.  
  36.            END
  37. */
  38.  
  39. //program coding starts from here
  40.  
  41.  
  42. #include <stdio.h>
  43. #define MAX_SIZE 16
  44.  
  45. int main()
  46. {
  47.  
  48. int w,a,N,J,o,clen;
  49. char cipher[MAX_SIZE];
  50. char plain_text[256], temp[256],temp1[16][256];
  51.  
  52. //Taking input length of cipher key from 2 to 16
  53. printf("Please enter length of cipher key between 2 to 16: ");
  54. scanf("%d",&w);
  55.  
  56. //Checking cipher key character length in between 2 to 16
  57. if(w<2  || w>16){
  58. do{
  59. printf("\nEntered cipher key length %d is not in between 2 to 16, Enter again: ",w);
  60. scanf("%d", &w);
  61. }while(w<2  ||  w>16);
  62. }
  63.  
  64. //Taking actual cipher key.
  65. printf("\nEnter cipher key of length %d :",w);
  66. scanf("%s", cipher);
  67. if(w!=strlen(cipher)){
  68. do{
  69. printf("\nEntered cipher key length is %d it must be %d, Enter again", strlen(cipher),w);
  70. scanf("%s",cipher);
  71. }while(w!=strlen(cipher));
  72. }
  73.  
  74. //Taking input of plain text from 4 to 256
  75. printf("\nPlease enter length of pain text between 4 to 256:");
  76. scanf("%d",&a);
  77.  
  78. //Checking plain text character length in between 4 to 256
  79. if(a<4  ||  a>256){
  80. do{
  81. printf("\nEntered plain text length %d is not in between 4 to 256, Enter again; ",a);
  82. scanf("%d",&a);
  83. }while(a<4  ||  a>256);
  84. }
  85.  
  86. //Taking atucal plain text.
  87. printf("\nEnter plain text of length %d:" ,a);
  88. //scanf("%s", plain_text);
  89. if(a!=strlen(plain_text)){
  90. do{
  91. printf("\nEntered plain text length is %d it must be %d, Enter again: ",strlen(plain_text),a);
  92. //scanf("%s", plain_text);
  93. scanf (" %[^\n]", plain_text);
  94. }while(a!=strlen(plain_text));
  95. }
  96.  
  97. strcpy(temp,plain_text);
  98. clen=strlen(cipher);
  99.  
  100. //Performing the encryption position V to target value N+1
  101. for(N=0; N<strlen(plain_text); N++){
  102. if(temp[0]==cipher[N]){
  103. plain_text[N]=cipher[N+1];
  104. }
  105. }
  106.  
  107. printf("\nStep 1 Substitute %c with %c", cipher[0],cipher[1]);
  108. printf("\n%s",plain_text)
  109.  
  110.  
  111. //Perfoming the encryption postion second position of cipher to target value second last
  112. for(J=1; J<clen-1; J++){
  113. for(N=0; N<strlen(plain_text);N++){
  114. if(cipher[J]==temp[N]){
  115. plain_text[N]=cipher[J+1];
  116. }
  117. }
  118.  
  119. printf("\nStep %d substitube %c with %c", J+1,cipher[J], cipher[J+1]);
  120. printf("\n%s",plain_text);
  121. }
  122.  
  123. //End of cipher key pointer
  124. for(N=0; N<strlen(plain_text); N++){
  125. if(cipher[clen-1]==temp[N]){
  126. plain_text[N]=cipher[0];
  127. }
  128. }
  129. printf("\nStep %d Substitube %c with %c", clen,cipher[clen-1],cipher[0]);
  130. printf("\n%s",plain_text);
  131.  
  132. return 0;
  133. }