Advertisement
Guest User

IntelliJ Code Generator

a guest
Nov 25th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.46 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.math.BigInteger;
  3. import java.util.Date;
  4. import java.util.Random;
  5. import java.util.zip.CRC32;
  6.  
  7. public class keygen
  8. {
  9.   /**
  10.   * @param s
  11.   * @param i
  12.   * @param bytes
  13.   * @return
  14.   */
  15.   public static short getCRC(String s, int i, byte bytes[])
  16.   {
  17.       CRC32 crc32 = new CRC32();
  18.       if (s != null)
  19.       {
  20.           for (int j = 0; j < s.length(); j++)
  21.           {
  22.               char c = s.charAt(j);
  23.               crc32.update(c);
  24.           }
  25.       }
  26.       crc32.update(i);
  27.       crc32.update(i >> 8);
  28.       crc32.update(i >> 16);
  29.       crc32.update(i >> 24);
  30.       for (int k = 0; k < bytes.length - 2; k++)
  31.       {
  32.           byte byte0 = bytes[k];
  33.           crc32.update(byte0);
  34.       }
  35.       return (short) (int) crc32.getValue();
  36.   }
  37.  
  38.   /**
  39.   * @param biginteger
  40.   * @return String
  41.   */
  42.   public static String encodeGroups(BigInteger biginteger)
  43.   {
  44.       BigInteger beginner1 = BigInteger.valueOf(0x39aa400L);
  45.       StringBuilder sb = new StringBuilder();
  46.       for (int i = 0; biginteger.compareTo(BigInteger.ZERO) != 0; i++)
  47.       {
  48.           int j = biginteger.mod(beginner1).intValue();
  49.           String s1 = encodeGroup(j);
  50.           if (i > 0)
  51.           {
  52.               sb.append("-");
  53.           }
  54.           sb.append(s1);
  55.           biginteger = biginteger.divide(beginner1);
  56.       }
  57.       return sb.toString();
  58.   }
  59.  
  60.   /**
  61.   * @param i
  62.   * @return
  63.   */
  64.   public static String encodeGroup(int i)
  65.   {
  66.       StringBuilder sb = new StringBuilder();
  67.       for (int j = 0; j < 5; j++)
  68.       {
  69.           int k = i % 36;
  70.           char c;
  71.           if (k < 10)
  72.           {
  73.               c = (char) (48 + k);
  74.           }
  75.           else
  76.           {
  77.               c = (char) ((65 + k) - 10);
  78.           }
  79.           sb.append(c);
  80.           i /= 36;
  81.       }
  82.       return sb.toString();
  83.   }
  84.  
  85.   /**
  86.   * @param name
  87.   * @param days
  88.   * @param id
  89.   * @param prtype
  90.   * @return
  91.   */
  92.   public static String MakeKey(String name, int days, int id, byte type, byte version)
  93.   {
  94.       id %= 100000;
  95.       byte bkey[] = new byte[12];
  96.       bkey[0] = type; // Product type: IntelliJ IDEA is 1
  97.       bkey[1] = version; // version
  98.       Date d = new Date();
  99.       long ld = (d.getTime() >> 16);
  100.       bkey[2] = (byte) (ld & 255);
  101.       bkey[3] = (byte) ((ld >> 8) & 255);
  102.       bkey[4] = (byte) ((ld >> 16) & 255);
  103.       bkey[5] = (byte) ((ld >> 24) & 255);
  104.       days &= 0xffff;
  105.       bkey[6] = (byte) (days & 255);
  106.       bkey[7] = (byte) ((days >> 8) & 255);
  107.       bkey[8] = 105;
  108.       bkey[9] = -59;
  109.       bkey[10] = 0;
  110.       bkey[11] = 0;
  111.       int w = getCRC(name, id % 100000, bkey);
  112.       bkey[10] = (byte) (w & 255);
  113.       bkey[11] = (byte) ((w >> 8) & 255);
  114.       BigInteger pow = new BigInteger("89126272330128007543578052027888001981", 10);
  115.       BigInteger mod = new BigInteger("86f71688cdd2612ca117d1f54bdae029", 16);
  116.       BigInteger k0 = new BigInteger(bkey);
  117.       BigInteger k1 = k0.modPow(pow, mod);
  118.       String s0 = Integer.toString(id);
  119.       String sz = "0";
  120.       while (s0.length() != 5)
  121.       {
  122.           s0 = sz.concat(s0);
  123.       }
  124.       s0 = s0.concat("-");
  125.       String s1 = encodeGroups(k1);
  126.       s0 = s0.concat(s1);
  127.       return s0;
  128.   }
  129.  
  130.   public static void main(String[] args) throws IOException, InterruptedException
  131.   {
  132.       Random r = new Random();
  133.       System.out.println(MakeKey("Steve Jobs", 0, r.nextInt(1000000), (byte) 1, (byte) 14));
  134.   }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement