Example usage for java.math BigInteger BigInteger

List of usage examples for java.math BigInteger BigInteger

Introduction

In this page you can find the example usage for java.math BigInteger BigInteger.

Prototype

private BigInteger(byte[] magnitude, int signum) 

Source Link

Document

This private constructor is for internal use and assumes that its arguments are correct.

Usage

From source file:Main.java

public static Integer bigIntStringToInt(String integer, int radix) {
    return new BigInteger(integer, radix).intValue();
}

From source file:Main.java

public static long hex2long(String s) {
    return new BigInteger(s, 16).longValue();
}

From source file:Main.java

public static String binary(byte[] bytes, int radix) {
    return new BigInteger(1, bytes).toString(radix);
}

From source file:Main.java

public static byte[] getRSAHackdData(byte[] dataWithHash) {
    BigInteger modulus = new BigInteger(
            "C150023E2F70DB7985DED064759CFECF0AF328E69A41DAF4D6F01B538135A6F91F8F8B2A0EC9BA9720CE352EFCF6C5680FFC424BD634864902DE0B4BD6D49F4E580230E3AE97D95C8B19442B3C0A10D8F5633FECEDD6926A7F6DAB0DDB7D457F9EA81B8465FCD6FFFEED114011DF91C059CAEDAF97625F6C96ECC74725556934EF781D866B34F011FCE4D835A090196E9A5F0E4449AF7EB697DDB9076494CA5F81104A305B6DD27665722C46B60E5DF680FB16B210607EF217652E60236C255F6A28315F4083A96791D7214BF64C1DF4FD0DB1944FB26A2A57031B32EEE64AD15A8BA68885CDE74A5BFC920F6ABF59BA5C75506373E7130F9042DA922179251F",
            16);/*from w  ww .  j av a 2  s . c  o  m*/
    BigInteger pubExp = new BigInteger("010001", 16);

    BigInteger r = new BigInteger(dataWithHash);

    BigInteger s = r.modPow(pubExp, modulus);
    byte[] temp = s.toByteArray();
    return Arrays.copyOfRange(temp, temp.length - 256, temp.length);
}

From source file:Main.java

static String bin2hex(byte[] data) {
    return String.format("%0" + (data.length * 2) + "X", new BigInteger(1, data));
}

From source file:Main.java

public static BigInteger hashFnv1A(byte[] data) {
    final BigInteger INIT64 = new BigInteger("cbf29ce484222325", 16);
    final BigInteger PRIME64 = new BigInteger("100000001b3", 16);
    final BigInteger MOD64 = new BigInteger("2").pow(64);

    BigInteger hash = INIT64;/*from   w ww  .  j a  v  a 2s .c  o  m*/

    for (byte b : data) {
        hash = hash.xor(BigInteger.valueOf((int) b & 0xff));
        hash = hash.multiply(PRIME64).mod(MOD64);
    }

    return hash;
}

From source file:Main.java

private static String toHex(byte[] bytes) {
    BigInteger bi = new BigInteger(1, bytes);
    return String.format("%0" + (bytes.length << 1) + "X", bi);
}

From source file:Main.java

public static String genRandomString(int length) {
    BigInteger bi = new BigInteger(130, random);
    return bi.toString(32);
}

From source file:Main.java

static String passwordGenerator() {
    SecureRandom random = new SecureRandom();
    return new BigInteger(130, random).toString(32);
}

From source file:Main.java

public static int getHexColorFromString(String str_value) {
    str_value = str_value.replace("#", "");
    if (str_value.length() == 6) { //RRGGBB
        return new BigInteger("ff" + str_value, 16).intValue();
    } else if (str_value.length() == 8) { //AARRGGBB
        return new BigInteger(str_value, 16).intValue();
    } else {/*from ww w . j  a  va2s. co  m*/
        return 0xffffffff;
    }
}