1 import java.io.BufferedReader;
2 import java.io.IOException;
3 import java.io.InputStreamReader;
4 import java.text.DecimalFormat;
5 import java.text.NumberFormat;
6 import java.text.SimpleDateFormat;
7 import java.util.Calendar;
8
9 public class MyEclipseKeyGen {
10 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.";
11
12 public String getSerial(String userId, String type) {
13 NumberFormat nf = new DecimalFormat("000");
14 Calendar cal = Calendar.getInstance();
15 cal.add(Calendar.YEAR, 3);
16 cal.add(Calendar.DAY_OF_YEAR, -1);
17 String licenseNum = nf.format((int) (Math.random() * 1000));
18 String expTime = new StringBuilder("-").append(
19 new SimpleDateFormat("yyMMdd").format(cal.getTime())).append(
20 "0").toString();
21 String need = new StringBuilder(userId.substring(0, 1)).append("Y")
22 .append(type).append("-100").append(licenseNum).append(expTime)
23 .toString();
24 String dx = new StringBuilder(need).append(LL).append(userId)
25 .toString();
26 int suf = this.decode(dx);
27 String code = new StringBuilder(need).append(String.valueOf(suf))
28 .toString();
29 return this.change(code);
30 }
31
32 private int decode(String s) {
33 int i;
34 char[] ac;
35 int j;
36 int k;
37 i = 0;
38 ac = s.toCharArray();
39 j = 0;
40 k = ac.length;
41 while (j < k) {
42 i = (31 * i) + ac[j];
43 j++;
44 }
45 return Math.abs(i);
46 }
47
48 private String change(String s) {
49 byte[] abyte0;
50 char[] ac;
51 int i;
52 int k;
53 int j;
54 abyte0 = s.getBytes();
55 ac = new char[s.length()];
56 i = 0;
57 k = abyte0.length;
58 while (i < k) {
59 j = abyte0[i];
60 if ((j >= 48) && (j <= 57)) {
61 j = (((j - 48) + 5) % 10) + 48;
62 } else if ((j >= 65) && (j <= 90)) {
63 j = (((j - 65) + 13) % 26) + 65;
64 } else if ((j >= 97) && (j <= 122)) {
65 j = (((j - 97) + 13) % 26) + 97;
66 }
67 ac[i] = (char) j;
68 i++;
69 }
70 return String.valueOf(ac);
71 }
72
73 public static void main(String[] args) {
74 try {
75 System.out.println("please input register name:");
76 BufferedReader reader = new BufferedReader(new InputStreamReader(
77 System.in));
78 String userId = null;
79 userId = reader.readLine();
80 if (userId == null || "".equals(userId)) {
81 System.out.println("name is null");
82 System.exit(0);
83 }
84 MyEclipseKeyGen myeclipsegen = new MyEclipseKeyGen();
85 String res = myeclipsegen.getSerial(userId, "E3MS");
86 System.out.println("Serial:" + res);
87 reader.readLine();
88 } catch (IOException ex) {
89 ex.printStackTrace();
90 }
91 }
92 }
转载于:https://www.cnblogs.com/roemin/archive/2011/09/08/2171331.html