- UID
 - 43331
 
 注册时间2007-12-27
阅读权限30
最后登录1970-1-1
龙战于野 
  
 
 
 
TA的每日心情  | 开心 2022-12-21 20:04 | 
|---|
 
  签到天数: 189 天 [LV.7]常住居民III  
 | 
 
从看雪精华里复制的 怎么编译不了 帮忙看看 哪里错了  谢谢了 
void CKeyGenDlg::OnOK()  
{ 
  // TODO: Add extra validation here 
  UpdateData(true); 
  char szKey[64],szReg[32]={0},szStr[32]={"yxb_200@"}; 
   
  //我的机器码 
  //m_Edit1 = "61326210431"; 
   
  //检查机器码的长度不小于 5 
  int iLength = m_Edit1.GetLength (); 
  if ( iLength < 5 ){ 
    m_Edit2 = "机器码应该至少 5 个数字"; 
    UpdateData(false); 
    return; 
  } 
   
  //机器码的前6位 + 接下来的6位 
  //即 613262 + 10431 = 623693 
  int iMac= atoi(m_Edit1.Mid (0,6)) + (iLength>6?atoi(m_Edit1.Mid (6,6)):0); 
   
  //机器码中的字符跟(szStr 中的字符对 10 的余数)循环异或 
  //得到 szKey = "6962>:514:4" 
  strcpy(szKey,m_Edit1); 
  for ( byte i=0; i<iLength; i++ ) szKey ^= (szStr[(i+1)%8]%10); 
   
  //取机器码相加结果 "623693" 的前 6 位 
  sprintf(szStr,"%06d",iMac);szStr[6]=0; 
   
  //szKey 的各个字符 ASC 求和并对 255 取余得到 90,作为 iSum 的初值 
  int iSum = 0; 
  for ( i=0; i<iLength; i++ ) iSum += szKey; 
  iSum %= 255; 
 
  //经过下面循环 iReg 转为十进制文本就是注册码了 
  __int64 iReg = 0; 
  iLength = strlen(szStr); 
  for( i=0; i<iLength; i++ ){ 
    iSum += szStr; 
    if( iSum > 255 ) iSum -= 255; 
    iSum ^= szKey; 
    iReg *= 256; 
    iReg += iSum; 
  } 
 
  //最后对注册码处理 
  _i64toa(iReg,szReg,10); 
  m_Edit2 = szReg; 
 
  //如果注册码没有 16 位,可以在注册码的随机位置插入随机字母 
  //这些字母在校验时会被去除 
  iLength = 15 - m_Edit2.GetLength (); 
  for ( i=0; i<iLength; i++ ){ 
    char cRand = 'A' + rand() % 26 ; 
    byte bIndex = rand() % iLength; 
    m_Edit2.Insert (bIndex,cRand); 
  } 
 
  //注册码的最后一位插入一个随机数字 
  m_Edit2.Insert (15,('0'+rand()%10)); 
 
  //用 '-' 将注册码分成四段 
  m_Edit2.Insert (4,'-'); 
  m_Edit2.Insert (9,'-'); 
  m_Edit2.Insert (14,'-'); 
  UpdateData(false); 
} |   
 
 
 
 |