Advertisement
Guest User

rail

a guest
Jul 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4.  
  5.  
  6. void main()
  7.  
  8. FILE*fp ;
  9. FILE*fp1 ;
  10. FILE*r;
  11. int n;
  12. int i,j,k,l;
  13. char a[100],c[100],d[100],h[100];
  14. char buf[100];
  15. char *p;
  16.  
  17.  
  18. fp=fopen("encrypted.txt","a");
  19. fp1=fopen("decrypted.txt","a");
  20. r=fopen("search.txt","a");
  21. printf("\nEnter Plain Text : ");
  22. gets(a);
  23. l=strlen(a);
  24.  
  25.  
  26. for(i=0,j=0;i<l;i++)
  27. {
  28. if(i%2==0)
  29. c[j++]=a[i];
  30. }
  31.  
  32.  
  33. for(i=0;i<l;i++)
  34. {
  35. if(i%2==1)
  36. c[j++]=a[i];
  37. }
  38.  
  39. c[j]='\0';
  40. printf("\n encrypted text : ",c);
  41. printf("\n %s",c);
  42.  
  43.  
  44. fprintf(fp," encrpyted text : %s \n ",c);
  45.  
  46. if(l%2==0)
  47. k=l/2;
  48. else
  49. k=(l/2)+1;
  50. for(i=0,j=0;i<k;i++)
  51. {
  52. d[j]=c[i];
  53. j=j+2;
  54. }
  55.  
  56. for(i=k,j=1;i<l;i++)
  57. {
  58. d[j]=c[i];
  59. j=j+2;
  60. }
  61. d[l]='\0';
  62.  
  63.  
  64. printf("\n decrypted text : ");
  65. printf(" \n %s",d);
  66.  
  67.  
  68. fprintf(fp1," decrypted text : %s \n",d);
  69.  
  70. fprintf(r," decrpyted text: %s\n" ,d);
  71.  
  72.  
  73. fclose(fp);
  74. fclose(fp1);
  75. fclose(r);
  76.  
  77. r=fopen("search.txt","r");
  78.  
  79. printf("\n \n \n ");
  80.  
  81. printf("search text:");
  82. gets(h);
  83.  
  84. while(fgets(buf,100,r))
  85. {
  86.  
  87. p=strstr(buf,h);
  88. if(p!=NULL){
  89.  
  90. printf( " \n word found: %s",p);
  91. n=1;
  92.  
  93. }
  94.  
  95. }
  96.  
  97. if (n!=1){
  98.  
  99.  
  100. printf("word not found");
  101.  
  102.  
  103.  
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement