Thursday, March 31, 2016

C program to implement receiver side confidentiality.

//Assumption: test1.txt is encrypted using Ceasar cipher (Key=3).

#include<stdio.h>
int main() {
 
   FILE *fp1, *fp2;
   char a;

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

   fp2 = fopen("test2.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("test1.txt is successfully decrypted and stored to test2.txt.");
  printf("\nUser can read test2.txt file.");
 
  fclose(fp1);
  fclose(fp2);
  return 0;
}
/*Output of program:
test1.txt is successfully decrypted and stored to test2.txt.
User can read test2.txt file.
*/

No comments:

Post a Comment