-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenkey.cpp
61 lines (50 loc) · 1.09 KB
/
Genkey.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/****************************************************************************/
void crcgen( unsigned long* crcTable )
{
unsigned long crc, poly;
int i, j;
poly = 0xEDB88320L;
for (i=0; i<256; i++) {
crc = i;
for (j=8; j>0; j--) {
if (crc&1) {
crc = (crc >> 1) ^ poly;
} else {
crc >>= 1;
}
}
crcTable[i] = crc;
}
}
/****************************************************************************/
unsigned long getcrc( unsigned long* crcTable, char* s, int size )
{
unsigned long crc = 0xFFFFFFFF;
for ( int cnt=0; cnt!=size; cnt++ )
{
int c = s[cnt];
crc = ((crc>>8) & 0x00FFFFFF) ^ crcTable[ (crc^c) & 0xFF ];
}
return ( crc^0xFFFFFFFF );
}
#ifdef GENKEY_PROJECT
#include <string.h>
#include <math.h>
#include <stdio.h>
__cdecl void main ( int argc, char** argv )
{
if ( argc<2 )
return;
unsigned long crcTable[256];
crcgen( crcTable );
char s[1024];
s[0] = 0;
for ( int i=1; i<argc; i++ )
{
strcat(s,argv[i]);
}
unsigned long crc = getcrc( crcTable, s, strlen(s) );
printf("User name = %s\n",s);
printf("Registration code = %d\n",abs(crc));
}
#endif