Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
381 views

Private Key File Encryption

This C program allows a user to encrypt or decrypt a file by shifting each character by the ASCII value of the first character of the file name. It prompts the user to choose encryption or decryption and then the file name. It opens the original and temporary files, reads each character, shifts it by the key, and writes it to the temporary file. It then closes and removes the original file and renames the temporary file to the original name, completing the encryption or decryption process.

Uploaded by

chhavish
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
381 views

Private Key File Encryption

This C program allows a user to encrypt or decrypt a file by shifting each character by the ASCII value of the first character of the file name. It prompts the user to choose encryption or decryption and then the file name. It opens the original and temporary files, reads each character, shifts it by the key, and writes it to the temporary file. It then closes and removes the original file and renames the temporary file to the original name, completing the encryption or decryption process.

Uploaded by

chhavish
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

//private key file Encryption-Decryption EXP-7

#include<stdio.h>

void main() {
FILE *fp,*fp1;

int choi; char name[20],temp[20]={"Temp.txt"},c; clrscr(); printf("

Press 1 to Encrypt: Press 2 to Decrypt"); printf("

Enter your Choice:"); scanf("%d",&choi); switch(choi) { case 1: printf("Enter the filename to Encrypt:");

scanf("%s",name); fp=fopen(name,"r+"); if(fp==NULL) { printf("The file %s can't be open",name); getch(); exit(); } fp1=fopen(temp,"w+"); if(fp1==NULL) { printf("The file Temp can't be open"); getch(); exit(); } c=fgetc(fp); while(c!=EOF) { fputc((c+name[0]),fp1);printf("%c",c+name[0]);getch(); c=fgetc(fp); } fclose(fp);

fclose(fp1); remove(name); rename(temp,name); printf("The file is Encrypted:"); getch(); break; case 2: printf("

Enter the Filename to Decrypt:"); scanf("%s",name); fp=fopen(name,"r+"); fp1=fopen(temp,"w+"); c=fgetc(fp); while(c!=EOF) { fputc(c-name[0],fp1); c=fgetc(fp); } fclose(fp); fclose(fp1); remove(name);

rename(temp,name); printf("The file is decrypted:"); getch(); } }

You might also like