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(long val) 

Source Link

Document

Constructs a BigInteger with the specified value, which may not be zero.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = new byte[] { (byte) 0x12, (byte) 0x0F, (byte) 0xF0 };

    // Create a BigInteger using the byte array
    BigInteger bi = new BigInteger(bytes);

    String s = bi.toString(2);/*from   ww w. j  a va  2s  . com*/
    System.out.println(s);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // A negative value
    byte[] bytes = new byte[] { (byte) 0xFF, 0x00, 0x00 }; // -65536
    // A positive value
    bytes = new byte[] { 0x1, 0x00, 0x00 }; // 65536
    BigInteger bi = new BigInteger(bytes);
}

From source file:MainClass.java

public static void main(String[] args) {
    System.out.println("Here's Long.MAX_VALUE: " + Long.MAX_VALUE);
    BigInteger bInt = new BigInteger("3419229223372036854775807");
    System.out.println("Here's a bigger number: " + bInt);
    System.out.println("Here it is as a double: " + bInt.doubleValue());
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    BigInteger p = new BigInteger(Integer.toString(pValue));
    BigInteger g = new BigInteger(Integer.toString(gValue));
    System.out.println("p = " + p);
    System.out.println("g = " + g);

    BigInteger Xa = new BigInteger(Integer.toString(XaValue));
    BigInteger Xb = new BigInteger(Integer.toString(XbValue));
    System.out.println("Xa = " + Xa);
    System.out.println("Xb = " + Xb);

    BigInteger Ya = g.modPow(Xa, p);
    System.out.println("Ya = " + Ya);

    BigInteger Yb = g.modPow(Xb, p);
    System.out.println("Yb = " + Yb);

    BigInteger Ka = Ya.modPow(Xa, p);
    System.out.println("Users A, K = " + Ka);

    BigInteger Kb = Yb.modPow(Xb, p);
    System.out.println("Users B, K = " + Kb);

}

From source file:BigNums.java

public static void main(String[] argv) {
    //+//from www . j  a v  a2  s. c o m
    System.out.println("Here's Long.MAX_VALUE: " + Long.MAX_VALUE);
    BigInteger bInt = new BigInteger("3419229223372036854775807");
    System.out.println("Here's a bigger number: " + bInt);
    System.out.println("Here it is as a double: " + bInt.doubleValue());
    //-
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    int eValue = 79;
    int bitLength = 1024; // KeySize

    BigInteger e = e = new BigInteger(Integer.toString(eValue));

    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(bitLength);//from   w w w.  j a  v  a 2 s  . c  o  m
    KeyPair kp = kpg.generateKeyPair();

    KeyFactory kfactory = KeyFactory.getInstance("RSA");
    RSAPublicKeySpec kspec = (RSAPublicKeySpec) kfactory.getKeySpec(kp.getPublic(), RSAPublicKeySpec.class);

    kpg = KeyPairGenerator.getInstance("RSA", "SunRsaSign");

    e = new BigInteger(Integer.toString(eValue));
    System.out.println("e =" + e);
    RSAKeyGenParameterSpec param = new RSAKeyGenParameterSpec(bitLength, e);
    kpg.initialize(param);
    kp = kpg.generateKeyPair();

    kfactory = KeyFactory.getInstance("RSA", "SunRsaSign");

    kspec = (RSAPublicKeySpec) kfactory.getKeySpec(kp.getPublic(), RSAPublicKeySpec.class);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    BigInteger p = new BigInteger(Integer.toString(pValue));
    BigInteger g = new BigInteger(Integer.toString(gValue));
    BigInteger Xa = new BigInteger(Integer.toString(XaValue));
    BigInteger Xb = new BigInteger(Integer.toString(XbValue));

    createKey();/* ww w .  ja  v a2  s . c  o  m*/

    int bitLength = 512; // 512 bits
    SecureRandom rnd = new SecureRandom();
    p = BigInteger.probablePrime(bitLength, rnd);
    g = BigInteger.probablePrime(bitLength, rnd);

    createSpecificKey(p, g);
}

From source file:Main.java

public static void main(String[] argv) {
    BigInteger l = new BigInteger("9999999");
    System.out.println(findPalindrome(l));

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL u = new URL("http://www.google.com");
    InputStream in = u.openStream();
    MessageDigest sha = MessageDigest.getInstance("SHA");
    byte[] data = new byte[1024];
    int bytesRead = -1;
    while ((bytesRead = in.read(data)) >= 0) {
        sha.update(data, 0, bytesRead);//from  w ww.  ja  v a 2  s  .  c  o  m
    }
    byte[] result = sha.digest();
    System.out.println(Arrays.toString(result));
    System.out.println(new BigInteger(result));
}

From source file:PalindromeBig.java

public static void main(String[] argv) {
    for (int i = 0; i < argv.length; i++)
        try {// w  w  w .  jav  a2  s  .co m
            BigInteger l = new BigInteger(argv[i]);
            if (l.compareTo(BigInteger.ZERO) < 0) {
                System.err.println(argv[i] + " -> TOO SMALL");
                continue;
            }
            System.out.println(argv[i] + "->" + findPalindrome(l));
        } catch (NumberFormatException e) {
            System.err.println(argv[i] + "-> INVALID");
        } catch (IllegalStateException e) {
            System.err.println(argv[i] + "-> " + e);
        }
}