Viruses today are not just designed to cause damage to your data and system but also to steal some of your sensitive information, hence it is very important today that you somehow protect your data in a manner, such that if in case it gets stolen, it is still not in a usable format to the second person……

This is done through Data Encryption.

Data Encryption is one of the many ways by which one can protect his sensitive data from getting stolen, or misused. Many different methods can be employed to encrypt a data.

So here a simple Program written in ‘C’ and ‘Batch’ that implements data encryption and its decryption of a text file.
You can easily store all your passwords in a text file and then encrypt it so that you have it safe with you.

‘Batch File’ part of the program:-

@echo off
echo Your password please!!
set/p “pass=>”
if NOT %pass%==hitachi goto FAIL
:start
cls
echo Enter the name of the file
set/p “cho=>”
cls
echo Press “E or e” for Encryption and “D or d” for Decryption.
set/p “input=>”
cls
if %input%==e goto encrypt
if %input%==d goto decrypt
:encrypt
ren %cho%.txt general.txt
encrypt.exe
ren encrypted.txt %cho%.txt
del general.txt
cls
echo Encryption Successful…..
goto end
:decrypt
ren %cho%.txt encrypted.txt
decrypt.exe
ren general.txt %cho%.txt
del encrypted.txt
cls
echo Decryption Successful…..
goto end
:FAIL
echo Dude Sharpen your Skills first…..BYE
exit
:end
Echo Press “x” to exit or “c” to continue….
set/p “end=>”
if %end%==x exit
if %end%==c goto start

‘C’ part of the program:-
For encryption:-

#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE *fp,*f;
char a;
int ch;
fp=fopen(“general.txt”,”a+”);
f=fopen(“encrypted.txt”,”a+”);
while(1)
{
a=fgetc(fp);
printf(“%c”,a);
if(a==EOF)
break;
ch=a+44;
a=ch;
fprintf(f,”%c”,a);

}
return 0;
}

For Decryption:-

#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE *fp,*f;
char a;
int ch;
fp=fopen(“general.txt”,”a+”);
f=fopen(“encrypted.txt”,”a+”);
while(1)
{
a=fgetc(f);
printf(“%c”,a);
if(a==EOF)
break;
ch=a-44;
a=ch;
fprintf(fp,”%c”,a);

}
return 0;
}

Note:-

1. First copy the batch program in notepad and save it by any name with the extension “.bat”.

2. Now copy the “C” part of the program one by one in any c editor(with compiler) and then build it to generate an
.exe file. Make sure that the c editor is capable of generating an exe file of the same bit as that of your operating system.Such as “Code Blocks”.

3. Copy the exe file in the same folder as that of your batch file.

4. You are good to go now….Run your batch file, type your password(here it is “hitachi” you can change it by replacing “hitachi” with any of your password in the batch file) and give the name of the file to be encrypted or decrypted.

Leave a Reply