Pages

Thursday, March 31, 2016

C program to implement sender side confidentiality.

//Create test.txt file with some text in the same folder where you are saving this program.

#include<stdio.h>

int main() {
 
   FILE *fp1, *fp2;
   char a;

   fp1 = fopen("test.txt", "r");
 
   if (fp1 == NULL) {
      puts("cannot open test.txt file.");
      exit(1);
   }

   fp2 = fopen("test1.txt", "w");
 
   if (fp2 == NULL) {
      puts("Not able to test1.txt file.");
      fclose(fp1);
      exit(1);
   }

   a = fgetc(fp1);
   fprintf(fp2,"%c",a+3);

   while(a != EOF)
   {
    a = fgetc(fp1);
    fprintf(fp2,"%c",a+3);
   }
 
  printf("test.txt is successfully encrypted and stored to test1.txt.");
  printf("\ntest1.txt can be forwarded to destination.");
 
  fclose(fp1);
  fclose(fp2);
  return 0;
}

/*Output of program
test.txt is successfully encrypted and stored to test1.txt.
test1.txt can be forwarded to destination.
*/

No comments:

Post a Comment