int _tmain(int argc, _TCHAR* argv[])
{
int data [9] = {0x4B,0x45,0x59,0x2D,0x4B,0x41,0x4E,0x4F,0x4E};
//用户名
char userName[100] = { 0 };
//用户名的长度
int userNameLen = 0;
//用户名的ASCII之和
unsigned int userNameSum = 0;
//存放值
unsigned int mulValue = 0;
unsigned int value = 0;
//商
unsigned int quotient = 0;
//余数
unsigned int mod = 0;
//校验码
unsigned int Checksum = 0;
//注册码
int decode[9] = {0};
//用户名求ASCII之和
for (int i = 0; i < userNameLen; i++)
{
userNameSum += userName[i];
}
//程序求出验证码
for (int i = 0; i < 9; i++)
{
mulValue = data[i] * userNameSum;
value = 0x1A;
quotient = mulValue / value;
mod = mulValue % value;
value = mod + 0x61;
value = value ^ 0xAA;
Checksum = Checksum + value;
}
//这里计算出Key值
int s1,s2,s3,s4,s5,s6,s7,s8,s9;
for (int a = 1; a <= 0xFF; a++)
{
s1 = a ^ 0xAA;
for (int b = 1; b <= 0xFF; b++)
{
s2 = b ^ 0xAA;
for (int c = 1; c <= 0xFF; c++)
{
s3 = c ^ 0xAA;
for (int d = 1; d <= 0xFF; d++)
{
s4 = d ^ 0xAA;
for (int e = 1; e <= 0xFF; e++)
{
s5 = e ^ 0xAA;
for (int f = 1; f <= 0xFF ; f++)
{
s6 = f ^ 0xAA;
for (int g = 1; g <= 0xFF; g++)
{
s7 = g ^ 0xAA;
for (int h = 1; h <= 0xFF; h++)
{
s8 = h ^ 0xAA;
for (int i = 1; i <= 0xFF; i++)
{
s9 = i ^ 0xAA;
if((s1+s2+s3+s4+s5+s6+s7+s8+s9) == Checksum)
{
decode[0] = a;
decode[1] = b;
decode[2] = c;
decode[3] = d;
decode[4] = e;
decode[5] = f;
decode[6] = g;
decode[7] = h;
decode[8] = i;
goto Exit;
}
}
}
}
}
}
}
}
}
}
Exit:
printf("注册码的十六进制串:");
for (int i = 0; i < 9; i++)
{
printf("%02X",decode[i]);
}
printf("\n注册码的字符串为:");
for (int i = 0; i < 9; i++)
{
printf("%c",decode[i]);
}
printf("\n");
return 0;
}