Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. public static short getCRC(String s, int i, byte bytes[]) {
  2. CRC32 crc32 = new CRC32();
  3. if (s != null) {
  4. for (int j = 0; j < s.length(); j++) {
  5. char c = s.charAt(j);
  6. crc32.update(c);
  7. }
  8. }
  9. crc32.update(i);
  10. crc32.update(i >> 8);
  11. crc32.update(i >> 16);
  12. crc32.update(i >> 24);
  13. for (int k = 0; k < bytes.length - 2; k++) {
  14. byte byte0 = bytes[k];
  15. crc32.update(byte0);
  16. }
  17. return (short) (int) crc32.getValue();
  18. }
  19.  
  20. public static String encodeGroups(BigInteger biginteger) {
  21. BigInteger beginner1 = BigInteger.valueOf(0x39aa400L);
  22. StringBuilder sb = new StringBuilder();
  23. for (int i = 0; biginteger.compareTo(BigInteger.ZERO) != 0; i++) {
  24. int j = biginteger.mod(beginner1).intValue();
  25. String s1 = encodeGroup(j);
  26. if (i > 0) {
  27. sb.append("-");
  28. }
  29. sb.append(s1);
  30. biginteger = biginteger.divide(beginner1);
  31. }
  32. return sb.toString();
  33. }
  34.  
  35. public static String encodeGroup(int i) {
  36. StringBuilder sb = new StringBuilder();
  37. for (int j = 0; j < 5; j++) {
  38. int k = i % 36;
  39. char c;
  40. if (k < 10) {
  41. c = (char) (48 + k);
  42. } else {
  43. c = (char) ((65 + k) - 10);
  44. }
  45. sb.append(c);
  46. i /= 36;
  47. }
  48. return sb.toString();
  49. }
  50.  
  51.  
  52. public static String MakeKey(String name, int days, int id) {
  53. id %= 100000;
  54. long ld = (new Date().getTime() >> 16);
  55. byte bkey[] = new byte[12];
  56. bkey[0] = (byte) 1; // Product type: IntelliJ IDEA is 1
  57. bkey[1] = 13; // version
  58. bkey[2] = (byte) (ld & 255);
  59. bkey[3] = (byte) ((ld >> 8) & 255);
  60. bkey[4] = (byte) ((ld >> 16) & 255);
  61. bkey[5] = (byte) ((ld >> 24) & 255);
  62. days &= 0xffff;
  63. bkey[6] = (byte) (days & 255);
  64. bkey[7] = (byte) ((days >> 8) & 255);
  65. bkey[8] = 105;
  66. bkey[9] = -59;
  67. bkey[10] = 0;
  68. bkey[11] = 0;
  69. int w = getCRC(name, id % 100000, bkey);
  70. bkey[10] = (byte) (w & 255);
  71. bkey[11] = (byte) ((w >> 8) & 255);
  72. BigInteger pow = new BigInteger("89126272330128007543578052027888001981", 10);
  73. BigInteger mod = new BigInteger("86f71688cdd2612ca117d1f54bdae029", 16);
  74. BigInteger k0 = new BigInteger(bkey);
  75. BigInteger k1 = k0.modPow(pow, mod);
  76. String s0 = Integer.toString(id);
  77. String sz = "0";
  78. while (s0.length() != 5) {
  79. s0 = sz.concat(s0);
  80. }
  81. s0 = s0.concat("-");
  82. String s1 = encodeGroups(k1);
  83. s0 = s0.concat(s1);
  84. return s0;
  85. }
  86.  
  87. public static void main(String[] args) {
  88. Random r = new Random();
  89. String name = "mr.X";
  90. System.out.println(name);
  91. System.out.println(MakeKey(name, 0, r.nextInt(100000)));
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement