Hello, I have a javascript file, and I want to translate it in C, I did it but I have a big runtime error. Everything work well until the end of the function when it return an int. If you have some ideas where the bug is. Thanks a lot.
#ifndef max
#define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
#endif
char *substring(size_t start, size_t stop, const char *src, char *dst, size_t size)
{
int count = stop - start;
if ( count >= --size )
{
count = size;
}
sprintf(dst, "%.*s", count, src + start);
return dst;
}
int CrackLog(char log[], char pw[])
{
int tabc=3696619; //7
char tab[]=" azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN0123456789_$&#@";
int i,checksum;
checksum=tabc;
int nblog=strlen(log);
int nbpass=6;//6
int sum=1;
int n = max(nblog,nbpass);
for (i=0;i<n;i++)
{
char *to;
to = substring(i, i+1, log, to, sizeof to);
int index1=strcspn(tab, to)+10;
to = substring(i, i+1, pw, to, sizeof to);
int index2=strcspn(tab, to)+10;
sum=sum+(index1*n*(i+1))*(index2*(i+1)*(i+1));
}
if (sum==checksum) {
return 1;
}else
return 0;
}
Forgive my english I am frensh. Mac Fly