I wrote this code for a school project,since i use vista and dos doesn't work properly on it ,i normally use the emulator DOSBOX.The problem is this program runs well on DOSBOX but not on the normal DOS platform. It gives an error
Floating point error:domain Abnormal program termination
Here's the code,its on text file encryption.My school requires me to use the ancient "turbo c++ 3.0"
#include<string.h>
#include<stdio.h>
#include<fstream.h>
#include<conio.h>
#include<math.h>
int strtoken(char k[]) {
int N = strlen(k);
int sum = 0 ;
for (int q=0;q<N;q++)
sum+= (int) k[q] ;
int tok = sum%255;
return tok;
}
int strtoken2(char k1[]) {
int N1 = strlen(k1);
int sum1 = 0,t=0;
for (int q1=0;q1<N1;q1++)
{
t = (int) k1[q1];
t=pow(2,t);
sum1+= (t%255) ;
}
int tok = sum1%255;
return tok;
}
int main() {
clrscr();
int choice,num;
char ifname[20],ofname[20],Key[20],ch;
start:
clrscr();
cout<<"\n------------------------------------------------------------------------------\n";
cout<<"Texcrypt 1.0.\n";
cout<<"\n";
cout<<"------------------------------------------------------------------------------\n\n";
cout<<"\t\t\t*-------------------*\n"<<"\t\t\t| 1) Encrypt. |\n"<<"\t\t\t| 2) Decrypt. |\n"<<"\t\t\t| 3) Help. |\n\t\t\t| 4) Exit. |\n"<<"\t\t\t*-------------------*\n";
cout<<"\nEnter your choice: ";
cin>>choice;
if(choice==3) {
clrscr();
cout<<" Instructions \n ------------- \n\n\n 1.Choose whether to encrypt or decrypt a file ";
cout<<"\n 2.Enter the input and output filenames (if the file is in same directory as texcrypt ,if not,then enter the full path of the file)";
cout<<"\n 3.Enter the key to encrypt/decrypt the file with(your file will be encrypted on the basis of the key entered).";
cout<<"\n 4.The output file will be your encrypted/decrypted file";
cout<<"\n\n\n\nPress any key to return ...... ";
getch();
goto start;
}
else if(choice==4)
return 0;
char text[3][20] = {"","encrypted","decrypted"};
clrscr();
cout<<"Enter input filename : ";
gets(ifname);
fflush(stdin);
cout<<"\n";
int i;
ifstream infile("");
ofstream outfile("");
infile.open(ifname);
if(!infile) { // if file is not found
cout<<"Error:File not found";
goto end;
}
cout<<"Enter output filename : ";gets(ofname);fflush(stdin);
cout<<"\n";
outfile.open(ofname);
switch(choice) {
case 1:cout<<"Enter key: ";
for(i=0;;i++)
{
Key[i]=getch();
if (Key[i] == '\r')
break;
cout<<"*";
}
Key[i] = '\0';
// I think the error is somewhere overhere
int token= strtoken(Key);
int token2= strtoken2(Key);
fflush(stdin);
cout<<"\n";
while (infile) {
while(infile){
infile.get(ch);
if(!infile){
cout<<"\nThe file was successfully encrypted.";
getch();
goto end;
}
ch=char((ch+token-(token2))%255);
outfile.put(ch);
}
}
break;
case 2:
cout<<"Enter key: ";
for(i=0;;i++){
Key[i]=getch();
if (Key[i] == '\r')
break;
cout<<"*";
}
Key[i] = '\0';
cout<<"\n";
fflush(stdin);
int dtoken=strtoken(Key);
int dtoken2=strtoken2(Key);
while(infile) {
while(infile) {
infile.get(ch);
if(!infile)
{
cout<<"\nThe file was successfully decrypted.";
getch();
goto end;
}
ch=char(((ch)-dtoken+(dtoken2))%255);
outfile.put(ch);
}
}
break;
}
//end switch
end:
infile.close();
outfile.close();
cout<<"\n\n\nPress any key to return ......... " ;
getch();
goto start;
return 0;
}