Wednesday 18 March 2015

Program to encrypt and decrypt a file Using C


# include <stdio.h>
# include <conio.h>

void main()
{
FILE *fptr;
char c ;
clrscr() ;
printf("Enter the text to be stored in the file.\n") ;
printf("Use ^Z or F6 at the end of the text and press
ENTER : \n\n") ;
fptr = fopen("ENCDEC.DAT","w") ;
while((c = getchar()) != EOF)
fputc(c, fptr) ;
fclose(fptr) ;
printf("\n\nData output in encrypted form : \n\n") ;
fptr = fopen("ENCDEC.DAT", "r") ;
while((c = fgetc(fptr)) != EOF)
printf("%c", c+1) ;
fclose(fptr) ;
printf("\n\nData output in decrypted form : \n\n") ;
fptr = fopen("ENCDEC.DAT", "r") ;
while((c = fgetc(fptr)) != EOF)
printf("%c", c) ;
fclose(fptr) ;
getch() ;
}


RUN 1 :
~~~~~~~
Enter the text to be stored in the file.
Use ^Z or F6 at the end of the text and press ENTER :
Computer Practice - II
D.D. Publications
^Z
Data output in encrypted form :
Dpnqvufs!Qsbdujdf!.!JJ
E/E/!Qvcmjdbujpot
Data output in decrypted form :
Computer Practice - II
D.D. Publications

No comments:

Post a Comment