110,566
社区成员
发帖
与我相关
我的任务
分享
public int[] intCode = new int[127];//用于存密钥
public void setIntCode()//给数组赋值个小于10的随机数
{
Random ra = new Random();
for (int i = 1; i < intCode.Length;i++ )
{
intCode[i] = ra.Next(0, 9);
}
}
public int[] intNumber = new int[25];//用于存机器码的Ascii值
public char[] Charcode = new char[25];//存储机器码字
//生成注册码
private void button2_Click(object sender, EventArgs e)
{
if (label2.Text != "")
{
//把机器码存入数组中
setIntCode();//初始化127位数组
for (int i = 1; i < Charcode.Length; i++)//把机器码存入数组中
{
Charcode[i] = Convert.ToChar(label2.Text.Substring(i - 1, 1));
}//
for (int j = 1; j < intNumber.Length; j++)//把字符的ASCII值存入一个整数组中。
{
intNumber[j] =
intCode[Convert.ToInt32(Charcode[j])] +
Convert.ToInt32(Charcode[j]);
}
string strAsciiName = null;//用于存储机器码
for (int j = 1; j < intNumber.Length; j++)
{
//MessageBox.Show((Convert.ToChar(intNumber[j])).ToString());
//判断字符ASCII值是否0-9之间
if (intNumber[j] >= 48 && intNumber[j] <= 57)
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
//判断字符ASCII值是否A-Z之间
else if (intNumber[j] >= 65 && intNumber[j] <= 90
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString());
}
//判断字符ASCII值是否a-z之间
else if (intNumber[j] >= 97 && intNumber[j] <= 122)
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
else//判断字符ASCII值不在以上范围内
{
if (intNumber[j] > 122)//判断字符ASCII值是否大于z
{
strAsciiName += Convert.ToChar(intNumber[j] - 10).ToString();
}
else
{
strAsciiName += Convert.ToChar(intNumber[j] - 9).ToString();
}
}
label3.Text = strAsciiName;//得到注册码
}
}
else
{ MessageBox.Show("请选生成机器码","注册提示"); }
}