#include<iostream.h>
#include<stdlib.h>
#include<stdio.h>
char encrypt(char c)
{
FILE *fp1, *fp2;
char ascii;
fp1 = fopen("subtable.txt","r");
fp2 = fopen("encrypted.txt","w");
//i need the code or right function here to get the character's or parameter's (char c) ascii code value from the subtable..
//for example, from the main program, a file to be encrypted will be read using fgetc()..fgetc reads single character from a stream that's why we uses a loop to read all characters until the end of file (EOF)..letter A is the first character to be read in file.txt..By calling fgetc() and encrypt(), letter A will be the parameter of function encrypt()..The question is, how could i get its ascii code value from the subtable..
//lettet 'A' should be returned as 'kEm'
return ascii;
}
char decrypt(char ascii)
{
FILE *fp;
char c;
fp = fopen("encrypted.txt","r");
//from this time, ascii is now the parameter..we're gonna get its character value from the subtable to decrypt it..
return c;
}
void main(void)
{
FILE *fp1, *fp2;
int choice;
char c, encfname[50], decfname[50];
cout<<"Please choose (1 - Encrypt || 2 - Decrypt): ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter filename where to save the encrypted one: ";
//for example, enter encrypted.txt
cin>>encfname;
fp1 = fopen("file.txt","r");
fp2 = fopen(encfname,"w");
c = fgetc(fp1);
while(c!=EOF)
{
fputc(encrypt(c),fp2);
c = fgetc(fp1);
}
break;
case 2:
cout<<"Enter filename where to save the decrypted one: ";
cin>>decfname;
fp1 = fopen("encrypted.txt","r");
fp2 = fopen(decfname,"w");
c = fgetc(fp1);
while(c!=EOF)
{
fputc(decrypt(c),fp2);
c = fgetc(fp1);
}
break;
}
}