void CCacheSNGenDlg::KeyGenerate(CString keyString)
{
char CryptStr[] = {'B','D','E','F','G','I','J','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'};
long BinaryStr[] = {
0x00, //00000 //B
0x10, //10000 //D
0x08, //01000 //E
0x18, //11000 //F
0x04, //00100 //G
0x14, //10100 //I
0x0C, //01100 //J
0x1C, //11100 //L
0x02, //00010 //M
0x12, //10010 //N
0x0A, //O
0x1A, //P
0x06, //Q
0x16, //R
0x0E, //S
0x1E, //T
0x01, //U
0x11, //V
0x09, //W
0x19, //X
0x05, //Y
0x15, //Z
0x0D, //0
0x1D, //1
0x03, //2
0x13, //3
0x0B, //4
0x1B, //5
0x07, //6
0x17, //7
0x0F, //8
0x1F, //11111 //9
0
};
int mask[] = {
0x03,
0x0F,
0x3F,
0xFF
};
char *c_id = new char[64];
long *lid = new long[5];
long *l_id = new long[5];
long *lSerial = new long[30];
CString encryptKey;
HCRYPTPROV cspContext;
HCRYPTHASH hashData;
DWORD dwHashLen;
BYTE *pbHash;
int i,j;
//FILE *fp;
//fp=fopen("mydata.txt","a");
encryptKey=keyString;
CryptAcquireContextW(&cspContext,NULL,NULL,1 ,0);
CryptCreateHash(cspContext,0x8003,0,0,&hashData);
CryptHashData(hashData,(const unsigned char *)encryptKey.GetBuffer(256),encryptKey.GetLength()+1,0);
CryptGetHashParam(hashData,2,NULL,&dwHashLen,0);
pbHash = (BYTE*)malloc(dwHashLen);
CryptGetHashParam(hashData,HP_HASHVAL,pbHash,&dwHashLen,0);
for (j = 0; j < 4; j++)
{
lid[j] = pbHash[ j * 4 + 0 ] << 24;
lid[j] |= pbHash[ j * 4 + 1 ] << 16;
lid[j] |= pbHash[ j * 4 + 2 ] << 8;
lid[j] |= pbHash[ j * 4 + 3 ];
l_id[j] = 0;
long ref = lid[j];
for(int i = 0; i < 32; i++)
{
if(ref & 1)
l_id[j] |= 1 << (31 - i);
ref >>= 1;
}
}
/////////////////////////////
long lSerialN = l_id[0];
for (int n = 0; n < 5; n++)
{
lSerial[0] = ( lSerialN >> 0 ) & 0x1F;
lSerial[1] = ( lSerialN >> 5 ) & 0x1F;
lSerial[2] = ( lSerialN >> 10 ) & 0x1F;
lSerial[3] = ( lSerialN >> 15 ) & 0x1F;
lSerial[4] = ( lSerialN >> 20 ) & 0x1F;
lSerial[5] = ( lSerialN >> 25 ) & 0x1F;
for (i=0;i<6;i++)
{
{
for (j = 31; j >= 0; j--) {
if ( BinaryStr[j] == lSerial[i])
{
c_id[n * 6 + i] = CryptStr[j];
break;
}
}
}
}
int shif = (n + 1) * 2;
lSerialN = ( l_id[n] >> (32 - shif) ) & mask[n];
lSerialN |= (l_id[n + 1] << shif);
}
c_id[26] = '\0';
strcpy(serialNumber,c_id);
free(c_id);
free(lid);
free(l_id);
free(lSerial);
//fprintf(fp,"%s", serialNumber);
//fclose(fp);
}