MyEclipse 序列号生成代码

根据程序运行提示输入用户名即可生成注册码

 1 import java.io.*;
 2 
 3 public class MyEclipseGen {
 4     private static final String LL = "Decompiling this copyrighted software is a violation of both your license agreement and the Digital Millenium Copyright Act of 1998 (http://www.loc.gov/copyright/legislation/dmca.pdf). Under section 1204 of the DMCA, penalties range up to a $500,000 fine or up to five years imprisonment for a first offense. Think about it; pay for a license, avoid prosecution, and feel better about yourself.";
 5 
 6     public String getSerial(String userId, String licenseNum) {
 7         java.util.Calendar cal = java.util.Calendar.getInstance();
 8         cal.add(1, 3);
 9         cal.add(6, -1);
10         java.text.NumberFormat nf = new java.text.DecimalFormat("000");
11         licenseNum = nf.format(Integer.valueOf(licenseNum));
12         String verTime = new StringBuilder("-").append(
13                 new java.text.SimpleDateFormat("yyMMdd").format(cal.getTime()))
14                 .append("0").toString();
15         String type = "YE3MP-";
16         String need = new StringBuilder(userId.substring(0, 1)).append(type)
17                 .append("300").append(licenseNum).append(verTime).toString();
18         String dx = new StringBuilder(need).append(LL).append(userId)
19                 .toString();
20         int suf = this.decode(dx);
21         String code = new StringBuilder(need).append(String.valueOf(suf))
22                 .toString();
23         return this.change(code);
24     }
25 
26     private int decode(String s) {
27         int i;
28         char[] ac;
29         int j;
30         int k;
31         i = 0;
32         ac = s.toCharArray();
33         j = 0;
34         k = ac.length;
35         while (j < k) {
36             i = (31 * i) + ac[j];
37             j++;
38         }
39         return Math.abs(i);
40     }
41 
42     private String change(String s) {
43         byte[] abyte0;
44         char[] ac;
45         int i;
46         int k;
47         int j;
48         abyte0 = s.getBytes();
49         ac = new char[s.length()];
50         i = 0;
51         k = abyte0.length;
52         while (i < k) {
53             j = abyte0[i];
54             if ((j >= 48) && (j <= 57)) {
55                 j = (((j - 48) + 5) % 10) + 48;
56             } else if ((j >= 65) && (j <= 90)) {
57                 j = (((j - 65) + 13) % 26) + 65;
58             } else if ((j >= 97) && (j <= 122)) {
59                 j = (((j - 97) + 13) % 26) + 97;
60             }
61             ac[i] = (char) j;
62             i++;
63         }
64         return String.valueOf(ac);
65     }
66 
67     public MyEclipseGen() {
68         super();
69     }
70 
71     public static void main(String[] args) {
72         try {
73             System.out.println("please input register name:");
74             BufferedReader reader = new BufferedReader(new InputStreamReader(
75                     System.in));
76             String userId = null;
77             userId = reader.readLine();
78             MyEclipseGen myeclipsegen = new MyEclipseGen();
79             String res = myeclipsegen.getSerial(userId, "20");
80             System.out.println("Serial:" + res);
81             reader.readLine();
82         } catch (IOException ex) {
83         }
84     }
85 }
View Code

 

转载于:https://www.cnblogs.com/PolarisSherlock/p/3662610.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
public synchronized String nextId() { long timestamp = timeGen(); //获取当前毫秒数 //如果服务器时间有问题(时钟后退) 报错。 if (timestamp < lastTimestamp) { throw new RuntimeException(String.format( "Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); } //如果上次生成时间和当前时间相同,在同一毫秒内 if (lastTimestamp == timestamp) { //sequence自增,因为sequence只有12bit,所以和sequenceMask相与一下,去掉高位 sequence = (sequence + 1) & sequenceMask; //判断是否溢出,也就是每毫秒内超过4095,当为4096时,与sequenceMask相与,sequence就等于0 if (sequence == 0) { timestamp = tilNextMillis(lastTimestamp); //自旋等待到下一毫秒 } } else { sequence = 0L; //如果和上次生成时间不同,重置sequence,就是下一毫秒开始,sequence计数重新从0开始累加 } lastTimestamp = timestamp; long suffix = (datacenterId << datacenterIdShift) | (workerId << workerIdShift) | sequence; String datePrefix = DateFormatUtils.format(timestamp, "yyyyMMddHHMMssSSS"); return datePrefix + suffix; } protected long tilNextMillis(long lastTimestamp) { long timestamp = timeGen(); while (timestamp <= lastTimestamp) { timestamp = timeGen(); } return timestamp; } protected long timeGen() { return System.currentTimeMillis(); } private byte getLastIP(){ byte lastip = 0; try{ InetAddress ip = InetAddress.getLocalHost(); byte[] ipByte = ip.getAddress(); lastip = ipByte[ipByte.length - 1]; } catch (UnknownHostException e) { e.printStackTrace(); } return lastip; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值