S-DEMO2 KEY MAKE (MODIFY A BUG) (2千字)
// Write by JMZZ 2002.06.24 (my Birthday)// Modify a bug 2002.06.25
// I don't see those code from 004080C7 to 004080ED
// during I tracked with SoftIce, sorry!
// A Name can have 16 Codes.
// Note: I don't test
// The length of Name
// CODE : 1 + 1 + 2 * sizeof(str4) + 1
// The length of Code must be 17.
// The first char is a char in the str1.
// The second char is controled by NameID or str2.
// The middle chars make pCode, pCode must be equal to str4.
// The last char is controled by the total index(offset).
#include "stdio.h"
#include "string.h"
typedef unsigned char BYTE ;
typedef unsigned long DWORD;
int main(void)
{
BYTE str1[]="FZRHK01WGTPQSAVC";
BYTE str2[]="Guest";
BYTE str3[]="WARE\0\0\0\0Guest\0\0\0";
BYTE str4[]="Clayman";
BYTE Name[20] ="\0";
BYTE sCode[18]="\0";
BYTE Id[12] ="\0";
BYTE NameId[100];
BYTE c;
DWORD NameIdLen , Index , i, j, k, jEbx, jEdx;
printf("Input Name:");
scanf("%s",Name);
printf("Input ID:");
scanf("%s",Id);
strcpy(NameId,Name);
strcat(NameId,Id);
NameIdLen = strlen(Name) + 11; // IdLen = 11
for(k=0;k<16;k+=1)
{
sCode[0] = str1[k];
Index= 15 - k;
i = NameIdLen % 7;
// if( i != 0)
// sCode[1]=str1[NameId[Index % i]&0x0f];
// else
// sCode[1]=str1[str2[Index % 5]&0x0f];
if( i != 0)
{
c = NameId[Index % i];
if((c & 0x80)==0x80) // support chinese
{
c = (((c & 0x8f - 1) | 0xf0) +1 ) & 0x0f;
if((c+1)%3 == 0)
sCode[0] = '\0';
// portion of sCode will be error!
// I don't know this,if you know ,please tell me!
//
sCode[1] = str3[c];
}
else
sCode[1]=str1[c&0x0f];
}
else
sCode[1]=str1[str2[Index % 5]&0x0f];
for(i=0;i< 7; i+=1) // 7 = (CodeLen-3)/2 // CodeLen = 17
{
jEbx = (str4[i] & 0xf0)>>4;
j =(- 0x80 + Index + jEbx) & 0x0f ;
sCode[2+2*i] = str1[j];
jEdx = str4[i] & 0x0f;
j =(- 0x80 + Index + jEdx) & 0x0f ;
sCode[2+2*i+1] = str1[j];
Index += jEbx;
}
sCode[2 + 2*i] = str1[(Index+17-3)&0x0f];
printf("Code= %s\n",sCode);
for(i=0;i<17;i+=1) sCode[i]='\0';
}
return 0;
}
