LackeyCCG

LackeyCCG Forum => Programming Help Forum => Topic started by: AuraDragon on November 22, 2015, 02:20:56 AM

Title: Shadows over Checksums
Post by: AuraDragon on November 22, 2015, 02:20:56 AM
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?
Title: Re: Shadows over Checksums
Post by: AuraDragon on November 22, 2015, 02:11:09 PM
...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