News:

A forum for users of LackeyCCG

Main Menu

Shadows over Checksums

Started by AuraDragon, November 22, 2015, 02:20:56 AM

Previous topic - Next topic

AuraDragon

Dear Trevor,

A long while back you posted your algorithm for generating checksums:

Quote from: Trevor, ages agoint GetCheckSumFromFile(char PathNamePart[])
{
    FILE* fp = FOpen(PathNamePart,"rb");
    if(fp==NULL)
        return 0; // If there is no file, return with a sum of 0.
    long f1,f2=0;
    char TempChar=0;
    int Sum=0;
    do
        {
        f1 = f2;
        TempChar = fgetc(fp);
        f2 = ftell(fp);
        if(TempChar!=10 && TempChar!=13)
            Sum+=(unsigned int)TempChar;
        Sum=Sum%100000000; //modulo to prevent memory type overflow               
        } while(f1 != f2);
    fclose(fp);
    return Sum;
}

I have since attempted to recreate that algorithm in C#, for the purpose of quickly obtaining checksums when updating.  However, my algorithm never produces the same value, no matter how much I tinker with it...  Did you, perchance, rewrite yours?

AuraDragon

...Apparently not, since I just compiled your code as a DLL (after much trial-and-error-and-hair-pulling) and implemented it in my tool and it worked exactly as intended!  :D