Sunday, March 17, 2019

Caesar Cipher - Decryption Program


Caesar Cipher - Decryption Program

This program will decrypt a given encrypted (Cipher Text) file using Caesar Cipher Decryption Cryptography Algorithm.

Assumptions: 

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


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

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

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

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

Output of program

cipher.txt file is successfully decrypted using Caesar Cipher.
plaintext.txt file is generated successfully.

Notes: This program will deduct 3 from ASCII value of each character of a given cipher text data file. A sample execution data is given below:

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

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

Content of plaintext.txt file after decryption using program:

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



Recommended Readings: Computer Security Practicals

No comments:

Post a Comment