Pages

Sunday, March 17, 2019

Caesar Cipher - File Encryption Program


Caesar Cipher - Encryption Program

This program will encrypt a given Data file using Caesar Cipher Cryptography Algorithm.

Assumptions: 




  • Caesar cipher key used is 3.
  • Input file name is: data.txt
  • Output file will be output.txt

#include<stdio.h>
int main() {
   FILE *inputFile, *outputFile;
   char ch;

   inputFile = fopen("data.txt", "r");
   if (inputFile == NULL) {
      puts("File data.txt Open Error.");
      exit(1);
   }

   outputFile = fopen("output.txt", "w");
   if (outputFile == NULL) {
      puts("File output.txt Open Error.");
      exit(1);
   }

   do {
      ch = fgetc(inputFile);
      fputc(ch+3, outputFile);
   } while (ch != EOF);
   
  printf("Data.txt file is successfully encrypted using Caesar Cipher.\n");
  printf("Output.txt file is generated successfully.");
  
  fclose(inputFile);
  fclose(outputFile);
  
  return 0;
}


Output of program


Data.txt file is successfully encrypted using Caesar Cipher.
Output.txt file is generated successfully.

Notes: This program will add 3 to ASCII value of each character of a given data file. A sample execution data is given below:

Original content of Data.txt input file before program execution:

Welcome to C Program Practicals.Blogspot.Com
This is Caesar Cipher Encryption Demonstration.

Content of Output.txt file after program encryption:

Zhofrph#wr#F#Surjudp#Sudfwlfdov1Eorjvsrw1Frp
Wklv#lv#Fdhvdu#Flskhu#Hqfu|swlrq#Ghprqvwudwlrq1


Recommended Readings: Computer Security Practicals


* * * * *


No comments:

Post a Comment