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[] args) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);

    MessageDigest md = MessageDigest.getInstance("MD5");
    SomeObject testObject = new SomeObject();

    dos.writeInt(testObject.count);//from w w w .  j  a v  a2  s.  co  m
    dos.writeLong(testObject.product);
    dos.writeDouble(testObject.stdDev);
    dos.writeUTF(testObject.name);
    dos.writeChar(testObject.delimiter);
    dos.flush();

    byte[] hashBytes = md.digest(baos.toByteArray());
    BigInteger testObjectHash = new BigInteger(hashBytes);

    System.out.println("Hash " + testObjectHash);

    dos.close();

}

From source file:edu.macalester.tagrelatedness.KendallsCorrelation.java

public static void main(String args[]) {
    long tiedx = new BigInteger("1853724906736").longValue();
    long tiedy = new BigInteger("5328254589").longValue();
    long numpairs = new BigInteger("4094164093575").longValue();
    BigSquareRoot sqrt = new BigSquareRoot();
    BigInteger first = new BigInteger("" + (numpairs - tiedx));
    BigInteger second = new BigInteger("" + (numpairs - tiedy));
    BigDecimal result = sqrt.get(first.multiply(second));
    System.out.println(result.doubleValue());

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(args[0]);
    java.security.cert.Certificate c = cf.generateCertificate(in);
    in.close();//from  www .j  a v a  2  s . c  o m

    X509Certificate t = (X509Certificate) c;
    System.out.println(t.getVersion());
    System.out.println(t.getSerialNumber().toString(16));
    System.out.println(t.getSubjectDN());
    System.out.println(t.getIssuerDN());
    System.out.println(t.getNotBefore());
    System.out.println(t.getNotAfter());
    System.out.println(t.getSigAlgName());
    byte[] sig = t.getSignature();
    System.out.println(new BigInteger(sig).toString(16));
    PublicKey pk = t.getPublicKey();
    byte[] pkenc = pk.getEncoded();
    for (int i = 0; i < pkenc.length; i++) {
        System.out.print(pkenc[i] + ",");
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    X509CertSelector selec = new X509CertSelector();
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(args[0]);
    Certificate c = cf.generateCertificate(in);
    System.out.println(selec.match(c));
    selec.setIssuer("CN=Peter,OU=Network Center," + "O=University,L=ZB,ST=Vancouver,C=CN");

    System.out.println(selec.match(c));

    Calendar cld = Calendar.getInstance();
    int year = Integer.parseInt(args[1]);
    int month = Integer.parseInt(args[2]) - 1;
    int day = Integer.parseInt(args[3]);
    cld.set(year, month, day);/*from  ww w  .j  a  v a 2  s . com*/
    Date d = cld.getTime();
    selec.setCertificateValid(d);

    System.out.println(selec.match(c));
    BigInteger sn = new BigInteger("1039056963");
    selec.setSerialNumber(sn);

    System.out.println(selec.match(c));
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    System.setProperty("javax.net.ssl.trustStore", "clienttrust");

    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 5432);

    SSLSession session = ((SSLSocket) s).getSession();
    Certificate[] cchain = session.getPeerCertificates();
    System.out.println("The Certificates used by peer");
    for (int i = 0; i < cchain.length; i++) {
        System.out.println(((X509Certificate) cchain[i]).getSubjectDN());
    }/*from   w w w  .j a  v a2s .  co m*/
    System.out.println("Peer host is " + session.getPeerHost());
    System.out.println("Cipher is " + session.getCipherSuite());
    System.out.println("Protocol is " + session.getProtocol());
    System.out.println("ID is " + new BigInteger(session.getId()));
    System.out.println("Session created in " + session.getCreationTime());
    System.out.println("Session accessed in " + session.getLastAccessedTime());

    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    String x = in.readLine();
    System.out.println(x);
    in.close();

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    System.setProperty("javax.net.ssl.keyStore", "lfkeystore2");
    System.setProperty("javax.net.ssl.keyStorePassword", "wshr.ut");

    SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    ServerSocket ss = ssf.createServerSocket(5432);
    while (true) {
        Socket s = ss.accept();//from www. j  a v a 2  s .c  o m
        SSLSession session = ((SSLSocket) s).getSession();
        Certificate[] cchain2 = session.getLocalCertificates();
        for (int i = 0; i < cchain2.length; i++) {
            System.out.println(((X509Certificate) cchain2[i]).getSubjectDN());
        }
        System.out.println("Peer host is " + session.getPeerHost());
        System.out.println("Cipher is " + session.getCipherSuite());
        System.out.println("Protocol is " + session.getProtocol());
        System.out.println("ID is " + new BigInteger(session.getId()));
        System.out.println("Session created in " + session.getCreationTime());
        System.out.println("Session accessed in " + session.getLastAccessedTime());

        PrintStream out = new PrintStream(s.getOutputStream());
        out.println("Hi");
        out.close();
        s.close();
    }

}

From source file:com.og.elliptic.sdk.main.java

public static void main(String[] args) {
    System.out.println("Test begins");

    WeierStrassCurve curve;/*from w  w  w  . ja v  a 2  s  .  c o  m*/
    BigInteger P = new BigInteger(
            "8884933102832021670310856601112383279507496491807071433260928721853918699951");
    BigInteger R = new BigInteger(
            "8094458595770206542003150089514239385761983350496862878239630488323200271273");
    BigInteger N = new BigInteger(
            "8884933102832021670310856601112383279454437918059397120004264665392731659049");
    BigInteger A4 = new BigInteger(
            "2481513316835306518496091950488867366805208929993787063131352719741796616329");
    BigInteger A6 = new BigInteger(
            "4387305958586347890529260320831286139799795892409507048422786783411496715073");
    BigInteger R4 = new BigInteger(
            "5473953786136330929505372885864126123958065998198197694258492204115618878079");
    BigInteger R6 = new BigInteger(
            "5831273952509092555776116225688691072512584265972424782073602066621365105518");
    BigInteger GX = new BigInteger(
            "7638166354848741333090176068286311479365713946232310129943505521094105356372");
    BigInteger GY = new BigInteger(
            "762687367051975977761089912701686274060655281117983501949286086861823169994");
    curve = new WeierStrassCurve(P, R, N, A4, A6, R4, R6, GX, GY);

    // testDiffieHelman(curve);
    //
    // testDiffieHelmanAndSign(curve);
    //
    // elGamalString(curve);

    testElGamal();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");

    List mylist = new ArrayList();

    FileInputStream in = new FileInputStream(args[0]);
    Certificate c = cf.generateCertificate(in);
    mylist.add(c);/*from   w  w  w . j a v a2 s  . c o  m*/

    CertPath cp = cf.generateCertPath(mylist);

    FileInputStream kin = new FileInputStream(args[0]);
    KeyStore ks = KeyStore.getInstance("JKS");
    ks.load(kin, args[1].toCharArray());

    PKIXParameters params = new PKIXParameters(ks);
    params.setRevocationEnabled(false);

    CertPathValidator cpv = CertPathValidator.getInstance("PKIX");

    PKIXCertPathValidatorResult result = (PKIXCertPathValidatorResult) cpv.validate(cp, params);

    PublicKey pbk = result.getPublicKey();
    byte[] pkenc = pbk.getEncoded();
    BigInteger pk = new BigInteger(pkenc);
    System.out.println(pk.toString(16));

    TrustAnchor anc = result.getTrustAnchor();
    X509Certificate xc = anc.getTrustedCert();
    System.out.println(xc.getSubjectDN());
    System.out.println(xc.getIssuerDN());

}

From source file:Ternary.java

public static void main(String[] args) {
    if (args.length == 0) {
        System.out.format("java org.eoti.lang.Ternary number [[number]...]\n");
        System.exit(0);/*from   ww  w .  ja v a 2s .c om*/
    }

    for (String arg : args) {
        BigInteger toConvert = new BigInteger(arg);
        Ternary ternary = new Ternary(toConvert);
        System.out.format("\nDecimal:\t%s\nTernary:\t%s\n", toConvert, ternary);
    }
}

From source file:RSA.java

/** Trivial test program. */
public static void main(String[] args) {
    RSA rsa = new RSA(1024);

    String text1 = "Yellow and Black Border Collies";
    System.out.println("Plaintext: " + text1);
    BigInteger plaintext = new BigInteger(text1.getBytes());

    BigInteger ciphertext = rsa.encrypt(plaintext);
    System.out.println("Ciphertext: " + ciphertext);
    plaintext = rsa.decrypt(ciphertext);

    String text2 = new String(plaintext.toByteArray());
    System.out.println("Plaintext: " + text2);
}