10 Replies - 515 Views - Last Post: 28 March 2009 - 01:38 AM Rate Topic: -----

#1 C++_beginner_me  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 18-March 09

Error when using my program!

Posted 27 March 2009 - 06:32 AM

Hello guys,

i'm using minGW compiler to compile my code. previousley i was able to execute any program, but now i've this error message when i'm trying to use my program (after compilin' it) , "This application has requested the runtime, to terminate it in an unusual way. please contact the application's support team for more information"

my os is; xp sp2

i tried to download the hotfix but it didn't work!!!


Please any one know how to solve this!!!!

Is This A Good Question/Topic? 0
  • +

Replies To: Error when using my program!

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 988
  • View blog
  • Posts: 5,135
  • Joined: 28-September 06

Re: Error when using my program!

Posted 27 March 2009 - 06:54 AM

You have tried a full reboot haven't you?
Was This Post Helpful? 0
  • +
  • -

#3 C++_beginner_me  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 18-March 09

Re: Error when using my program!

Posted 27 March 2009 - 07:02 AM

yes i did :(
Was This Post Helpful? 0
  • +
  • -

#4 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 988
  • View blog
  • Posts: 5,135
  • Joined: 28-September 06

Re: Error when using my program!

Posted 27 March 2009 - 07:14 AM

And you are sure it's the compiler throwing the error and not a bug in your program?

It's hard to tell from what you have shared.

I'd suggest downloading a different compiler and testing against that.

Have a look at the resources pinned at the top of the page for options.

The real answer IMO get a Mac or run Linux on your box (dual-boot if you wish).
Using a Unix-based OS will avoid having to use Windows-ported compilers.

This post has been edited by janotte: 27 March 2009 - 07:15 AM

Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,215
  • Joined: 23-August 08

Re: Error when using my program!

Posted 27 March 2009 - 07:47 AM

Show us your program.
Was This Post Helpful? 0
  • +
  • -

#6 ccubed  Icon User is offline

  • It's That Guy
  • member icon

Reputation: 153
  • View blog
  • Posts: 1,394
  • Joined: 13-June 08

Re: Error when using my program!

Posted 27 March 2009 - 08:14 AM

Well, if it compiles, then the compiler is doing its job. This means that somewhere in your code there's probably an error. I bet if you ran it in a debugging environment you'd get some kind of error. If you want to use MingW, have you tried Dev-C++? It's and IDE wrapped around MingW with debugging.
Was This Post Helpful? 0
  • +
  • -

#7 C++_beginner_me  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 18-March 09

Re: Error when using my program!

Posted 27 March 2009 - 11:25 AM

this is the programe
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
#include<cmath>
using namespace std;
int menu();
string per1(string), string LEFS1(string), string LEFS2(string), string per2(string), string IPRE(string), string IPREINVERSE(string), string EP(string), string StrBx1(string), string StrBx2(string), string Switch(string), string Ro1(string, string), string Ro2(string, string), string inFile();
int main()
{
ofstream outfile;
string fName;
string ciphertxt = "";
string pltxt = "";
string totalinfo = "";
string key = "";
string Pkey = "";
string Lkey = "";
string Rkey = "";
string Ckey = "";
string key1 = "";
string key2 = "";
string modtxt = "";
string subtxt = "";
int length = 0;
int total = 0;
int count = 0;
int method = 0;
int halflen =0;
int ikey = 0;
while (method != 3) 


{
method = menu();

switch (method)


{
case 1:
totalinfo = inFile();

//String Formatting and Separation
key = totalinfo.substr(0,10); //key assigned to key portion
totalinfo.erase(0,10);//erase the key portion
pltxt = totalinfo;//assign pltxt portion
//Key Modification
Pkey = per1(key);
Lkey = Pkey.substr(0,5);
Rkey = Pkey.substr(5,10);
Lkey = LEFS1(Lkey);
Rkey = LEFS1(Rkey);
Ckey = Lkey + Rkey;
key1 = per2(Ckey);
Lkey = LEFS2(Lkey);
Rkey = LEFS2(Rkey);
Ckey = Lkey + Rkey;
key2 = per2(Ckey);

/ start encryption /
total = pltxt.length() / 2; //determine how many encryptions are needed
for (count = 0; count < total; count++)


{

subtxt = pltxt.substr(0,8);
modtxt = IPRE(subtxt);//Run IPRE routine
modtxt = Ro1(modtxt, key1);
modtxt = Switch(modtxt);

modtxt = Ro2(modtxt, key2);
modtxt = IPREINVERSE(modtxt);

cout<<modtxt;
ciphertxt += modtxt; //for output
pltxt.erase(0,8); //advance to next pltxt block
}
cout<<"\nPlease enter fName for output(full path c:\test.txt)"<<endl;
cin>> fName;
outfile.open(fName.c_str());
if (outfile.is_open())


{
outfile <<ciphertxt<<endl;
}
else
cout<<"could not write to file"<<endl;
break;
//Decryption
case 2:

totalinfo = inFile();
//String Formatting and Separation
key = totalinfo.substr(0,10); //key assigned to key portion
totalinfo.erase(0,10);//erase the key portion
ciphertxt = totalinfo;//assign pltxt portion
//Key Modification
Pkey = per1(key);
Lkey = Pkey.substr(0,5);
Rkey = Pkey.substr(5,10);
Lkey = LEFS1(Lkey);
Rkey = LEFS1(Rkey);
Ckey = Lkey + Rkey;
key1 = per2(Ckey);
Lkey = LEFS2(Lkey);
Rkey = LEFS2(Rkey);
Ckey = Lkey + Rkey;
key2 = per2(Ckey);

/start Decryption /
total = ciphertxt.length() / 2; //determine how many encryptions are needed
for (count = 0; count < total; count++)


{
subtxt = ciphertxt.substr(0,8);
modtxt = IPRE(subtxt);//Run IPRE routine
modtxt = Ro1(modtxt, key2);
modtxt = Switch(modtxt);

modtxt = Ro2(modtxt, key1);
modtxt = IPREINVERSE(modtxt);

cout<<modtxt<<endl;

ciphertxt += modtxt; //for output

ciphertxt.erase(0,8); //advance to next ciphertxt block
}

cout<<"Please enter fName for output (full path c:\test.txt)"<<endl;
cin>> fName;
outfile.open(fName.c_str());
if (outfile.is_open())


{
   outfile <<ciphertxt<<endl;// write the encrypted data to the new file
}
else
cout<<"could not write to file"<<endl;
break;

case 3:
cout<<"Bye"<<endl;
}

}

return 0;
}

// input file
string inFile()


{
ifstream inFile;
string pltxt;
string key;
string totalinfo;
string fName;
int i = 0;
cout<<"Please enter fName for input (full path c:\test.txt)"<<endl;
cin>> fName;
inFile.open(fName.c_str(), ios :: in);
if ( !inFile )


{
cout << "check your entry!! " << endl;
return 0;
}

while ( !inFile.eof() ) 


{
getline( inFile,key);
getline( inFile,pltxt);
}
inFile.close();

key.erase(0,2);
pltxt.erase(0,2);
while ((pltxt.length() % 8) != 0)


{
pltxt += '0';
}
totalinfo = key + pltxt; 
return totalinfo;
}

int menu()


{
int method;
cout<<" choose one of the following "<<endl;
cout<<"1. Encrypt File"<<endl;
cout<<"2. Decrypt File"<<endl;
cout<<"3. Exit"<<endl;
cin >> method;
return method;
}

string per1(string key)


{

string permutation = key;
permutation[0] = key[2];
permutation[1] = key[4];
permutation[2] = key[1];
permutation[3] = key[6];
permutation[4] = key[3];
permutation[5] = key[9];
permutation[6] = key[0];
permutation[7] = key[8];
permutation[8] = key[7];
permutation[9] = key[5];
return permutation;
}

string LEFS1(string key)


{
string shky = key; 
shky[0] = key[1];
shky[1] = key[2];
shky[2] = key[3];
shky[3] = key[4];
shky[4] = key[0];
return shky;
}

string per2(string key)


{

string cpression = "";
cpression += key[5];
cpression += key[2];
cpression += key[6];
cpression += key[3];
cpression += key[7];
cpression += key[4];
cpression += key[9];
cpression += key[8];
return cpression;
}

string LEFS2(string key)


{
string shky = key;
shky[0] = key[2];
shky[1] = key[3];
shky[2] = key[4];
shky[3] = key[0];
shky[4] = key[1];
return shky;
}

string IPRE(string text)


{

string permutation = text;
permutation[0] = text[1];
permutation[1] = text[5];
permutation[2] = text[2];
permutation[3] = text[0];
permutation[4] = text[3];
permutation[5] = text[7];
permutation[6] = text[4];
permutation[7] = text[6];
return permutation;
}

string Ro1(string modtxt, string key1)


{
string L1 = modtxt.substr(0,4);
string R1 = modtxt.substr(4,8); 
string Rhold = R1;
modtxt = "0000"; 
string RightR1 ="";
string LeftR1 = "";
string Combo = "";

R1 = EP(R1);
// XOR with Key
int temp[8];
for (int i = 0; i < 8; i++)


{
temp[i] = int(R1[i]) ^ int(key1[i]);
R1[i] = temp[i] + 48;
}

// S-bx Substitutions
LeftR1 = R1.substr(0,4); //Separate Text
RightR1 = R1.substr(4,8); 
LeftR1 = StrBx1(LeftR1);
RightR1 = StrBx2(RightR1);
// P4 Permutation
Combo = LeftR1 + RightR1;
string Perm = Combo;
Perm[0] = Combo[1];
Perm[1] = Combo[3];
Perm[2] = Combo[2];
Perm[3] = Combo[0];

int temp2[4];
for (int i = 0; i < 4; i++)


{
temp2[i] = int(L1[i]) ^ int(Perm[i]);
modtxt[i] = temp2[i] + 48;
}

modtxt = modtxt + Rhold;
return modtxt;
}

string EP(string text)


{

string permutation = "";
permutation += text[3];
permutation += text[0];
permutation += text[1];
permutation += text[2];
permutation += text[1];
permutation += text[2];
permutation += text[3];
permutation += text[0];
return permutation;
}

string StrBx1(string text)


{
int subValue = 0;
string value = "00";
int row;
int col;
string r = text.substr(0,1) + text.substr(3);
string c = text.substr(1,2);
if (r == "00"){row = 0;} else if (r == "01"){row = 1;} else if (r == "10"){row = 2;} else row = 3;
if (c == "00"){col = 0;} else if (c == "01"){col = 1;} else if (c == "10"){col = 2;} else col = 3;
int bx[4][4]; //item[row_number] [column_number].
bx[0][0] = 1; bx[0][1] = 0; bx[0][2] = 3; bx[0][3] = 2;
bx[1][0] = 3; bx[1][1] = 2; bx[1][2] = 1; bx[1][3] = 0;
bx[2][0] = 0; bx[2][1] = 2; bx[2][2] = 1; bx[2][3] = 3;
bx[3][0] = 3; bx[3][1] = 1; bx[3][2] = 3; bx[3][3] = 2;
subValue = bx[row][col];
if (subValue == 0){value = "00";} else if (subValue == 1){value = "01";} else if (subValue == 2){value = "10";} else value = "11";
return value;
}

string StrBx2(string text)


{
int subValue = 0;
string value = "00";
int row;
int col;
string r = text.substr(0,1) + text.substr(3);
string c = text.substr(1,2);
if (r == "00"){row = 0;} else if (r == "01"){row = 1;} else if (r == "10"){row = 2;} else row = 3;
if (c == "00"){col = 0;} else if (c == "01"){col = 1;} else if (c == "10"){col = 2;} else col = 3;
int bx[4][4]; //item[row_number] [column_number].
bx[0][0] = 0; bx[0][1] = 1; bx[0][2] = 2; bx[0][3] = 3;
bx[1][0] = 2; bx[1][1] = 0; bx[1][2] = 1; bx[1][3] = 3;
bx[2][0] = 3; bx[2][1] = 0; bx[2][2] = 1; bx[2][3] = 0;
bx[3][0] = 2; bx[3][1] = 1; bx[3][2] = 0; bx[3][3] = 3;
subValue = bx[row][col];
if (subValue == 0){value = "00";} else if (subValue == 1){value = "01";} else if (subValue == 2){value = "10";} else value = "11";
return value;
}

string Switch(string text)


{
string left = text.substr(0, 4);
string right = text.substr(4, 8);
string modtxt = right + left;
return modtxt;
}

string Ro2(string modtxt, string key2)


{
string L1 = modtxt.substr(0,4); //Separate Text
string R1 = modtxt.substr(4,8); //Separate Text
string Rhold = R1;
modtxt = "0000";
string RightR1 ="";
string LeftR1 = "";
string Combo = "";

R1 = EP(R1);
// XOR with Key
int temp[8];
for (int i = 0; i < 8; i++)


{
temp[i] = int(R1[i]) ^ int(key2[i]);
R1[i] = temp[i] + 48;
}

// S-bx Substitutions
LeftR1 = R1.substr(0,4); //Separate Text
RightR1 = R1.substr(4,8); 
LeftR1 = StrBx1(LeftR1);
RightR1 = StrBx2(RightR1);
// P4 Permutation
Combo = LeftR1 + RightR1;
string Perm = Combo;
Perm[0] = Combo[1];
Perm[1] = Combo[3];
Perm[2] = Combo[2];
Perm[3] = Combo[0];
// Function f
int temp2[4];
for (int i = 0; i < 4; i++)


{
temp2[i] = int(L1[i]) ^ int(Perm[i]);
modtxt[i] = temp2[i] + 48;
}

modtxt = modtxt + Rhold;
return modtxt;
}

string IPREINVERSE(string text)


{

string permutation = text;
permutation[0] = text[3];
permutation[1] = text[0];
permutation[2] = text[2];
permutation[3] = text[4];
permutation[4] = text[6];
permutation[5] = text[1];
permutation[6] = text[7];
permutation[7] = text[5];
return permutation;
}




Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,215
  • Joined: 23-August 08

Re: Error when using my program!

Posted 27 March 2009 - 01:58 PM

Sorry, that doesn't even compile on gcc, which is what's underneath MinGW. I don't think you can declare all your prototypes separated by commas, and you have comments that are not proper /* */.

Also, for the love of Pete, indent your code :(
Was This Post Helpful? 0
  • +
  • -

#9 C++_beginner_me  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 18-March 09

Re: Error when using my program!

Posted 27 March 2009 - 02:28 PM

but if i just edit the code by removing the commas, and edit the comments it will compile (i tried this before), but i'm having the previous error message when i'm trying to encrypt or decrypt a file :(
so do you see any problem with the structure of defining the algorithm?

"" Also, for the love of Pete, indent your code ""

sorry i didn't get the point of that :(
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,215
  • Joined: 23-August 08

Re: Error when using my program!

Posted 27 March 2009 - 03:39 PM

Your code is not indented at all.

Anyway, when I tried your program there was an empty string coming back from the inFile function, which causes the substr() function call on it to crash.
Was This Post Helpful? 0
  • +
  • -

#11 C++_beginner_me  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 18-March 09

Re: Error when using my program!

Posted 28 March 2009 - 01:38 AM

so what should i do to fix this problem :(
would you please tell me how to fix it ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1