Encryptor and Decryptor in C
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include <unistd.h>
void pass();
void enc();
void dec();
void menu();
void load();
int main()
{
pass();
}
void pass()
{
printf("\n\n\n\t\t \xB2\xB2\xB2\xB2\xB2\xB2\xB2 DENcryptor \xB2\xB2\xB2\xB2\xB2\xB2\xB2\n\n");
printf(" \t\t \xb2 DEN Key is the secret code for\n\t\t your encryption and decryption \n\n\n");
menu();
}
void menu()
{
printf("\n\t\t \xB2\xB2\xB2\xB2\xB2 Press (e) to Encrypt\n\n\t\t \xB2\xB2\xB2\xB2\xB2 Press (d) to Decrypt\n\n\t\t ");
char sl;
switch(getch())
{
case 'e':
enc();
break;
case 'd':
dec();
break;
default:
menu();
}
}
void enc()
{
system("CLS");
char filen[20], ch, choice;
int key;
printf("\t\t Enter a DEN Key.(Numbers Only)\n\t\t Remember your DEN Key as it is\n\t\t required later to Decrypt properly\n\t\t =");
scanf("%d",&key);
fflush(stdin);
FILE *fps, *fpt;
printf("\t\t Make sure you have the .txt file in program directory\n \t\t Remember put .txt after file name\n ");
printf("\t\t Enter file name to encrypt: \n\t\t =");
gets(filen);
fps=fopen(filen, "r");
if(fps==NULL)
{
printf("\t\t Error in opening file..!!");
printf("\n\t\t Press any key to exit...\n\n\n\n\n");
getch();
exit(1);
}
fpt=fopen("temp.txt", "w");
if(fpt==NULL)
{
printf("\t\t Error in creating temp.txt file..!!");
fclose(fps);
printf("\n\t\t Press any key to exit...");
getch();
exit(2);
}
while(1)
{
ch=fgetc(fps);
if(ch==EOF)
{
break;
}
else
{
ch=ch+key;
fputc(ch, fpt);
}
}
fclose(fps);
fclose(fpt);
fps=fopen(filen, "w");
if(fps==NULL)
{
printf("\t\t Error in opening source file..!!");
printf("\n\t\t Press any key to exit...");
getch();
exit(3);
}
fpt=fopen("temp.txt", "r");
if(fpt==NULL)
{
printf("\t\t Error in opening temp.txt file...!!");
fclose(fps);
printf("\n Press any key to exit...");
getch();
exit(4);
}
while(1)
{
ch=fgetc(fpt);
if(ch==EOF)
{
break;
}
else
{
fputc(ch, fps);
}
}
load();
printf("\t\t File %s encrypted successfully..!!\n\n\n\n", filen);
fclose(fps);
fclose(fpt);
}
dec()
{
system("CLS");
char ch, choice, storage[20];
int key;
printf("\t\t Enter DEN Key\n\t\t previously used to decrypt this file.\n\t\t =");
scanf("%d",&key);
fflush(stdin);
FILE *fps, *fpt;
printf("\t\t Make sure you have the .txt file in program directory\n\t\t Remember put .txt after file name\n ");
printf("\t\t Enter file name to decrypt : \n\t\t =");
gets(storage);
fps=fopen(storage, "w");
if(fps==NULL)
{
printf("\t\t Error in opening source file..!!");
printf("\n\t\t Press any key to exit...");
getch();
exit(7);
}
fpt=fopen("temp.txt", "r");
if(fpt==NULL)
{
printf("\t\t Error in opening temp.txt file..!!");
fclose(fps);
printf("\n\t\t Press any key to exit...");
getch();
exit(9);
}
while(1)
{
ch=fgetc(fpt);
if(ch==EOF)
{
break;
}
else
{
ch=ch-key;
fputc(ch, fps);
}
}
load();
printf("\t\t File %s decrypted successfully..!!\n\n\n\n",storage);
printf("\n\t\t Press any key to exit...");
fclose(fps);
fclose(fpt);
getch();
}
void load()
{
int amount=20;
for ( int loop = 0; loop < 1; ++loop) {
for ( int each = 0; each < 5; ++each) {
printf ( "\rLOADING%.*s \b\b\b", each, ">>>");
printf(" %d%%",amount);
amount=amount+20;
fflush ( stdout);
sleep (1);
}
}
printf ( "\n");
system("cls");
}

Comments
Post a Comment