Create an encryption program Create a program with two optio
Solution
#include<stdio.h>
#include<stdlib.h>
int main()
{
//Two file pointers to read and write
FILE *fm, *few, *fdw;
char ch;
//Opens the file for reading
fm = fopen(\"Message.txt\", \"r\");
//Opens the file for writing
few = fopen(\"Encrypted.txt\", \"w\");
//Checks whether the file can able to open or not
if (fm == NULL)
{
printf(\"I could not open Message.txt for reading.\ \");
exit(0);
}
else
{
while (!feof(fm))
{
//Reads the characters from the file
fscanf(fm, \"%c \", &ch);
ch = ch + 15;
//Writes the encrypted characters to the file
fprintf(few, \"%c\", ch);
}
}
//Close both the files
fclose(fm);
fclose(few);
//Reopens Encrypted file in read mode
few = fopen(\"Encrypted.txt\", \"r\");
//Opens the Decrypted file in write mode
fdw = fopen(\"Decrypted.txt\", \"w\");
while (!feof(few))
{
//Reads the encrypted characters from the file
fscanf(few, \"%c\", &ch);
ch = ch - 15;
//Writes the decrypted characters to the file
fprintf(fdw, \"%c\", ch);
}
//Close both the files
fclose(few);
fclose(fdw);
}
