Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Acess Violation

Status
Not open for further replies.

al5f1nx

Programmer
Apr 12, 2004
4
IT
i've got a problem that is bugging me for hours now.
i wrote in c++ a simple decrypting program to decrypt a given file ( path given in the source ). when i compile it from DEV C++ it gives me no errors so it should be fine. when trying to run ( in windows ) i get "xyz.exe has genereted errors and it will be closed". trying another debuger i get " access violation when reading [00000000] ".
does anybody know what this might mean?
i have basically tried all sort of tricks but i cannot make it run . it is such an easy prog and i cannot get where the problem is !
any comment is appreciated
 
Yeah, post your program.

> i get " access violation when reading [00000000] ".
does anybody know what this might mean?
In all likelyhood, you have an uninitialised pointer (or more specifically in this case, a NULL pointer)


--
 
ok this is the source :

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

char *buf;
int key;
unsigned int GetCheckSum(char *buf, int key)
{
unsigned int checksum = 0;
unsigned int i = 0;
for(i = 0; i < 5; i++)
checksum += buf ^ key;
return checksum;
}


char retChar(char letter)
{
return letter;
}


void decrypt(std::string&)
{
int a,b,c,d,e,f,g,total;

for(a=97;a<=122;a++)
{
for(b=97;b<=122;b++)
{
for(c=97;c<=122;c++)
{
for(d=97;d<=122;d++)
{
for(e=97;e<=122;e++)
{
for(f=97;f<=122;f++)
{
for(g=97;g<=122;g++)
{

total=a+b+c+d+e+f+g+'n';

if(GetCheckSum(buf,key)==3530)
{
cout << retChar(a) << retChar(b) << retChar(c) << retChar(d) << retChar(e) << retChar(f) << retChar(g) << "...OK " << endl;
}

}
}
}
}
}
}
}
}



int main()
{
string crypted="encrypted.enc",cr;
ifstream crypt(crypted.c_str());

crypt >> cr;
decrypt(cr);
return 0;
}


thnx in advance
 
Code:
if(GetCheckSum(buf,key)==3530)

Neither buf nor key is ever given a value...ie could be anything. Initialize them properly.

/Per

&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;
 
That is right...but after initializing them i am at the exect same point
 
void decrypt(std::string&)
//??? where is the name of parameter you're passing in the
// function?

Ion Filipski
1c.bmp
 
With proper initialization they do work, however:

1.
Code:
for(i = 0; i < 5; i++)
checksum += buf[i] ^ key;
Obviously this means that buf must be at least 5 chars long.

2. for for for for
Every for is 25 iterations 97...122
You have 7 nested for loops.
25^7 = 6103515625
its gonna take a while....


3. Consider using conar char* instead if char*.

4. Consider not using global variables but rather declare 'em where needed.


/Per

&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;
 
Sorry, slippery keyboard.

3 should read:
3. Consider using const char* instead if char*.


/Per

&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top