Random Number Generator Windows 95

151 views Asked by At

I am making a Windows 95 CD Key generator. It uses a random number generator to generate a windows 95 CD Key. NOT an OEM key. I am having a problem. Here is my code:

int main() {
    win95cdkey();

    return 0;
}

int win95cdkey() {
    srand(time(0));
    int chunk1 = (rand() % (100 - 998 +1)) + 998;
    if(chunk1 = 333, 444, 555, 666, 777, 888, 999) {
        chunk1 = 635;
    }
    int chunk2[7];
    chunk2[0, 1, 2, 3, 4, 5, 6] = 6;
    while((chunk2[0] + chunk2[1] + chunk2[2] + chunk2[3] + chunk2[4] + chunk2[5] + chunk2[6]) % 7 !=  0) {
        printf("Brute Forcing...\n");
        printf("DEBUG\nchunk2[0]: %d\nchunk2[1]: %d\nchunk2[2]: %d\nchunk2[3]: %d\nchunk2[4]: %d\nchunk2[5]: %d\nchunk2[6]: %d\n",chunk2[0], chunk2[1], chunk2[2], chunk2[3], chunk2[4], chunk2[5], chunk2[6]);
        for(int i = 0; i <= 5; i++) {
            chunk2[0, 1, 2, 3, 4, 5] = 6;
            chunk2[i] = (rand() % (9 - 1 +1)) + 1;
        }
        chunk2[6] = (rand() % (7 - 1 +1)) + 1;
    }

    printf("FINAL DEBUG\nchunk2[0]: %d\nchunk2[1]: %d\nchunk2[2]: %d\nchunk2[3]: %d\nchunk2[4]: %d\nchunk2[5]: %d\nchunk2[6]: %d\n",chunk2[0], chunk2[1], chunk2[2], chunk2[3], chunk2[4], chunk2[5], chunk2[6]);
    printf("Key: %d-%d%d%d%d%d%d%d",chunk1 , chunk2[0], chunk2[1], chunk2[2], chunk2[3], chunk2[4], chunk2[5], chunk2[6]);
}

When I run it, if you look at the first debug it makes, the numbers are 8312038. A.K.A, a huge, invalid number. I don't know why, but my while loop thinks the number is divisible by 7. This is the output of running it in rapid succession for about a minute until this happened, it will sometimes also generate valid keys:

./a.out
FINAL DEBUG
chunk2[0]: -149060448
chunk2[1]: 32619
chunk2[2]: -1649141939
chunk2[3]: 21858
chunk2[4]: 0
chunk2[5]: 0
chunk2[6]: 6
Key: 635--14906044832619-164914193921858006

This is when it generates a valid key:

/a.out
Brute Forcing...
DEBUG
chunk2[0]: 1493075104
chunk2[1]: 32732
chunk2[2]: 117143373
chunk2[3]: 22053
chunk2[4]: 0
chunk2[5]: 0
chunk2[6]: 6
Brute Forcing...
DEBUG
chunk2[0]: 6
chunk2[1]: 1
chunk2[2]: 1
chunk2[3]: 6
chunk2[4]: 7
chunk2[5]: 8
chunk2[6]: 1
Brute Forcing...
DEBUG
chunk2[0]: 6
chunk2[1]: 8
chunk2[2]: 1
chunk2[3]: 3
chunk2[4]: 9
chunk2[5]: 2
chunk2[6]: 7
Brute Forcing...
DEBUG
chunk2[0]: 1
chunk2[1]: 8
chunk2[2]: 5
chunk2[3]: 7
chunk2[4]: 6
chunk2[5]: 1
chunk2[6]: 2
Brute Forcing...
DEBUG
chunk2[0]: 8
chunk2[1]: 4
chunk2[2]: 1
chunk2[3]: 7
chunk2[4]: 6
chunk2[5]: 3
chunk2[6]: 5
Brute Forcing...
DEBUG
chunk2[0]: 7
chunk2[1]: 7
chunk2[2]: 3
chunk2[3]: 1
chunk2[4]: 7
chunk2[5]: 2
chunk2[6]: 3
Brute Forcing...
DEBUG
chunk2[0]: 4
chunk2[1]: 9
chunk2[2]: 3
chunk2[3]: 8
chunk2[4]: 5
chunk2[5]: 3
chunk2[6]: 5
Brute Forcing...
DEBUG
chunk2[0]: 3
chunk2[1]: 2
chunk2[2]: 1
chunk2[3]: 1
chunk2[4]: 9
chunk2[5]: 6
chunk2[6]: 1
Brute Forcing...
DEBUG
chunk2[0]: 6
chunk2[1]: 4
chunk2[2]: 9
chunk2[3]: 4
chunk2[4]: 5
chunk2[5]: 7
chunk2[6]: 3
FINAL DEBUG
chunk2[0]: 8
chunk2[1]: 8
chunk2[2]: 3
chunk2[3]: 3
chunk2[4]: 5
chunk2[5]: 4
chunk2[6]: 4
Key: 635-8833544

I have no idea why this is happening. I've tried changing the variable to unsigned / static. I've also tried changing the rand() functions to random() functions. Can someone help me out?

Sorry if this is inaccurate, I'm new to coding.

0

There are 0 answers