Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java Security  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 哪位大哥能将这段代码所求的注册码算出来啊。小弟有急用啊。
zzr



发贴: 0
积分: 0
于 2003-07-03 10:19 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
private boolean isValidSerialNo()
{
String s = tfSerialNo.getText().trim();
boolean flag= s.length() == 22 && s.charAt ( 6 ) == '-' && s.charAt(15)== '-';
if (flag)
{
CRC32 crc32 = new CRC32();
crc32.update(s.substring(0,18).getBytes());
long l = crc32.getvalue;
l = l & 65535L ^ l >> 16 & 65535L;
flag = Long.parseLong(s.substring(18,22),16)==l;
}
if (flag)
tfSeriaNo.setTextMoon;
else
tfSeriaNo.requestFocus();
return flag;
}



作者 Re:哪位大哥能将这段代码所求的注册码算出来啊。小弟有急用啊。 [Re:zzr]
drum

保护视力

CJSDN高级会员


发贴: 168
积分: 52
于 2003-07-03 14:05 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.util.zip.CRC32;
public class Test{
  public static void main(String args[])throws Exception
  {
while(true)
{
  byte b[] = new byte[16];
  System.out.println("Please input a String of length >=16,EXIT is\"c\"");
  System.in.read(b,0,16);
  String s = new String( b ).trim();
  System.in.skip(System.in.available());
  if(16>s.length())
  {
   if(s.equalsIgnoreCase("c"))
   break;
   System.out.print("Warning: ");
   continue;
}
s = s.substring(0,6)+"-"+s.substring(6,14)+"-"+s.substring(14);
CRC32 crc32 = new CRC32();
crc32.update(s.substring(0,18).getBytes());
long l = crc32.getValue();
  l = l & 65535L ^ l >> 16 & 65535L;
  String temp = Long.toHexString(l);
  for(int i=0;i<4-temp.length();i++)
   temp = "0"+temp;
  s = s+temp;
  System.out.println("Serial code :"+s);
}  
}
}




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923