探知,不断发现
探知不断发现
 private void button1_Click(object sender, EventArgs e)
        
{
            textBox1.Text 
= GenerateNewKey("$BE$T$"102false500);
        }

        
public static string GenerateNewKey(string strSecurityCode, int nProductCode, bool bTrial, int nTrialDays)
        
{
            
if (!strSecurityCode.Equals("$BE$T$"))
            
{
                
return "";
            }

            
string str = Guid.NewGuid().ToString().Replace("-""");
            
string str2 = "";
            
if (bTrial)
            
{
                str2 
= "2" + nTrialDays.ToString("D3"+ "00000000" + nProductCode.ToString("D3");
            }

            
else
            
{
                str2 
= "1123ABCDEFGH" + nProductCode.ToString("D3");
            }

            
char[] chArray = (str + "$" + str2).ToCharArray();
            
byte[] inArray = new byte[chArray.Length];
            
for (int i = 0; i < chArray.Length; i++)
            
{
                inArray[i] 
= (byte)chArray[i];
            }

            
string strKey = Convert.ToBase64String(inArray);
            
string str4 = GetStringCheckSumValue(strKey).ToString("D3");
            
return (strKey + str4);
        }


 

        
public static int GetStringCheckSumValue(string strKey)
        
{
            
int i1 = 0;
            
byte b2 = 1;
            
for (int i2 = 0; i2 < strKey.Length; i2++)
            
{
                
byte b1 = (byte)strKey[i2];
                
for (int i3 = 0; i3 < 8; i3++)
                
{
                    
if ((b1 & (b2 << (i3 & 31))) == 0)
                        i1
++;
                }

            }

            
return i1;
        }


posted on 2007-10-17 17:13  lovebanyi  阅读(556)  评论(1编辑  收藏  举报