Escolar Documentos
Profissional Documentos
Cultura Documentos
//
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "math.h"
#include <ctype.h>
#define MAX_LEN 16
#define MAX_STR 1024
#ifndef WIN32
void strlwr(char *str) {
int n = strlen(str);
for (int i=0; i<n; i++) {
str[i] = tolower(str[i]);
}
}
#endif
class CRC6
{
const unsigned R;
const char W;
const char WBits;
const unsigned Mask;
unsigned* States;
public:
CRC6(char* Key, char* S, bool Encrypt=true, unsigned short Depth=3) :
R((Depth+2)<<2), W(32), WBits(5), Mask(0x1F), States(0)
{
if (!strcmp(S,"")) return;
States = (unsigned*) malloc((unsigned int)(W*(2*R+4)));
if (strlen(Key) > 255) Key[255] = 0;
if (Encrypt)
{
int Length = (strlen(S) + (4 * sizeof(unsigned)) - 1) & ~0xF;
Encode(Key, (unsigned*)S, Length);
}
}
virtual ~CRC6()
{
if (!States) return;
memset(States, rand(), (size_t)(W*(2*R+4)));
free(States);
}
private:
unsigned RotateL(unsigned x, unsigned Bits) {Bits &= Mask; return (x>>(W-
Bits)) | (x<<Bits);}
unsigned RotateR(unsigned x, unsigned Bits) {Bits &= Mask; return (x<<(W-
Bits)) | (x>>Bits);}
char Data[MAX_STR];
int i;
memset(Data, 0, sizeof(Data));
strcpy(Data, argv[1]);
strlwr(Data);
HashString(Data);
int L = strlen(Data);
if (L > MAX_LEN)
strcpy(Data, &Data[L-MAX_LEN]);
else
for (i = 0; i < MAX_LEN - L; i++) {
memmove(Data+1, Data, strlen(Data));
Data[0]=' ';
}
char Key[MAX_STR];
strcpy(Key, "violet14");
CRC6(Key, Data);
char Serial[MAX_STR];
memset(Serial, 0, sizeof(Serial));
Data2ASCIIHex(Data, Serial);
char sKey[MAX_STR];
memset(sKey, 0, sizeof(sKey));
int j = 0;
for (i = 0; i < (int)strlen(Serial); i++)
{
sKey[j++] = Serial[i];
if ((i % 4 == 3) && (i < (int)strlen(Serial)- 1)) sKey[j++] = '-';
}
//---------------
strcpy(Serial, sKey);
printf("1.5,%s\n", Serial);
return 0;
}