注册验证及注册机文档格式.docx

上传人:b****5 文档编号:21653564 上传时间:2023-01-31 格式:DOCX 页数:19 大小:50.20KB
下载 相关 举报
注册验证及注册机文档格式.docx_第1页
第1页 / 共19页
注册验证及注册机文档格式.docx_第2页
第2页 / 共19页
注册验证及注册机文档格式.docx_第3页
第3页 / 共19页
注册验证及注册机文档格式.docx_第4页
第4页 / 共19页
注册验证及注册机文档格式.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

注册验证及注册机文档格式.docx

《注册验证及注册机文档格式.docx》由会员分享,可在线阅读,更多相关《注册验证及注册机文档格式.docx(19页珍藏版)》请在冰豆网上搜索。

注册验证及注册机文档格式.docx

importjavax.swing.JOptionPane;

publicclassRegretVerifyextendsFrameimplementsActionListener

{

/****************成员变量*********************/

privateFontfont=newFont("

宋体"

Font.PLAIN,15);

privatePanelpanel1=newPanel();

privateLabellabel1=newLabel("

生成码:

"

);

privateLabellabel2=newLabel("

注册码:

privateTextFieldtextFiled1=newTextField();

privateTextFieldtextFiled2=newTextField();

privateButtonbutton1=newButton("

注册"

privateButtonbutton2=newButton("

取消"

/****************构造方法*********************/

privateRegretVerify(Stringtitle,StringiconPath)

{

this.setTitle(title);

this.setSize(420,150);

this.setBackground(Color.WHITE);

this.setLayout(null);

this.setResizable(false);

this.setLocationRelativeTo(null);

this.setIconImage(newImageIcon(iconPath).getImage());

this.panel1.setSize(420,150);

this.label1.setBounds(20,40,45,25);

this.label2.setBounds(20,75,45,25);

this.textFiled1.setBounds(70,40,320,25);

this.textFiled1.setEditable(false);

this.textFiled1.setFont(font);

this.textFiled2.setBounds(70,75,320,25);

this.textFiled2.setFont(font);

this.button1.setBounds(85,110,80,25);

this.button2.setBounds(255,110,80,25);

this.textFiled1.setText(createCode());

this.button1.addActionListener(this);

this.button2.addActionListener(this);

this.panel1.setLayout(null);

this.panel1.add(label1);

this.panel1.add(label2);

this.panel1.add(textFiled1);

this.panel1.add(textFiled2);

this.panel1.add(button1);

this.panel1.add(button2);

this.add(panel1);

//注册窗口关闭事件

this.addWindowListener(newWindowAdapter()

{

publicvoidwindowClosing(WindowEvente)

{

System.exit(0);

}

});

this.setVisible(true);

}

/****************按钮事件监听*********************/

publicvoidactionPerformed(ActionEvente)

if(e.getSource().equals(button1))

System.out.println(handleString(textFiled1.getText()));

if(handleString(textFiled1.getText()).equals(textFiled2.getText()))

JOptionPane.showMessageDialog(null,"

恭喜你!

注册成功!

"

提示"

JOptionPane.INFORMATION_MESSAGE);

else

注册码错误!

JOptionPane.WARNING_MESSAGE);

}

elseif(e.getSource().equals(button2))

this.dispose();

/*******************产生生成码*********************/

//生成随机的生成码

privateStringcreateCode()

StringmachineCode="

;

StringselectionStr="

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Randomrandom=newRandom();

inttimes=0;

for(inti=1;

i<

=32;

i++)

if(times==4)//生成结果每四个字符用“-”分隔

machineCode+="

-"

+selectionStr.charAt(random.nextInt(36));

times=0;

machineCode+=selectionStr.charAt(random.nextInt(36));

times++;

returnmachineCode;

/*****************核心算法*********************/

//将字符串的每个字符的ASC码转换为二进制字符串

privateStringstrToBinary(Stringstr)

StringbinStr="

for(inti=0;

i<

str.length();

charc=str.charAt(i);

//遍历字符串的每个字符

if(Integer.toBinaryString(c).length()==8)

{

binStr+=Integer.toBinaryString(c);

}

switch(Integer.toBinaryString(c).length())

case7:

binStr+="

0"

+Integer.toBinaryString(c);

break;

case6:

00"

case5:

000"

case4:

0000"

case3:

00000"

case2:

000000"

case1:

0000000"

default:

returnbinStr;

//处理一行字符串方法

privateStringhandleString(Stringstr)

StringbinStr=strToBinary(str);

//转换为对应ASC码的二进制字符串

StringfindValueInTable="

//对二进制字符串长度处理

if(binStr.length()%24==0)

findValueInTable=binChangeToChar(binStr);

if(binStr.length()%24==8)

binStr+="

findValueInTable=binChangeToChar(binStr)+"

=="

if(binStr.length()%24==16)

="

returnfindValueInTable;

//调用核心处理方法返回最终结果

//将二进制字符串转换为十进制数据,并拆分为6位一段进行查参照表,将查找到的字符累加返回

privateStringbinChangeToChar(StringbinStr)

HashMap<

Integer,Character>

hashTable=createTable();

//创建参照表

String[]binStrArr=binStrToArr(binStr);

//将二进制字符串转换为十进制字符串

inttimes=0;

binStrArr.length;

BigIntegerbigInt=newBigInteger(binStrArr[i],2);

//大数整型对象

StringdecStr=bigInt.toString(10);

//转换为指定进制的字符串

//将最终查表返回的字符串进行拆分为长度为4的字串,并以“_”分隔

if(times==4)

findValueInTable+="

+hashTable.get(Integer.parseInt(decStr));

times=0;

else

times++;

returnfindValueInTable.substring(0,39);

//由于返回长度大于生成码,截取和生成码长度相同的字符

//将二进制串转换为每个元素长度为6个字符的数组

privateString[]binStrToArr(StringbinStr)

String[]binStrArr=newString[binStr.length()/6];

for(inti=0,j=0;

binStr.length();

i+=6,j++)

if(i<

binStr.length()-6)

binStrArr[j]=binStr.substring(i,i+6);

}

binStrArr[j]=binStr.substring(i);

returnbinStrArr;

//建立映射表(用哈希Map)

privateHashMap<

createTable()

hashTable=newHashMap<

();

charvalue='

A'

=9;

i++)//0-9存储A-J

hashTable.put(i,value);

value++;

value='

0'

for(inti=10;

=19;

i++)//10-19存储0-9

K'

for(inti=20;

=34;

i++)//20-34存储K-Y

Z'

for(inti=35;

=60;

i++)//35-60存储Z-A

value--;

//61-63存储B-D

hashTable.put(61,'

B'

hashTable.put(62,'

C'

hashTable.put(63,'

D'

returnhashTable;

/***************供外界直接调用的方法*********************/

publicstaticvoidcreate(Stringtitle,StringiconPath)

newRegretVerify(title,iconPath);

/***************用于测试的主方法*********************/

publicstaticvoidmain(String[]args)

create("

regret/1.jpg"

}

注册机(破解上面注册码的):

publicclassRegretMachineextendsFrameimplementsActionListener

/**************成员变量*********************/

生成注册码"

关闭"

/*************构造方法*********************/

privateRegretMachine(StringiconPath)

this.setTitle("

注册机"

this.textFiled2.setEditable(false);

/***************按钮事件监听*********************/

if(textFiled1.getText().equals("

))

请输入生成码!

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 外语学习 > 法语学习

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1