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:org.jasig.cas.adaptors.x509.authentication.handler.support.ResourceCRLRevocationCheckerTests.java

/**
 * Gets the unit test parameters./* w ww.ja va 2  s.  com*/
 *
 * @return  Test parameter data.
 */
@Parameters
public static Collection<Object[]> getTestParameters() {
    final Collection<Object[]> params = new ArrayList<Object[]>();

    final ThresholdExpiredCRLRevocationPolicy zeroThresholdPolicy = new ThresholdExpiredCRLRevocationPolicy();
    zeroThresholdPolicy.setThreshold(0);

    // Test case #1
    // Valid certificate on valid CRL data
    params.add(new Object[] {
            new ResourceCRLRevocationChecker(
                    new ClassPathResource[] { new ClassPathResource("userCA-valid.crl"), }),
            zeroThresholdPolicy, new String[] { "user-valid.crt" }, null, });

    // Test case #2
    // Revoked certificate on valid CRL data
    params.add(new Object[] {
            new ResourceCRLRevocationChecker(
                    new ClassPathResource[] { new ClassPathResource("userCA-valid.crl"),
                            new ClassPathResource("intermediateCA-valid.crl"),
                            new ClassPathResource("rootCA-valid.crl"), }),
            zeroThresholdPolicy,
            new String[] { "user-revoked.crt", "userCA.crt", "intermediateCA.crt", "rootCA.crt" },
            new RevokedCertificateException(new Date(), new BigInteger("1")), });

    // Test case #3
    // Valid certificate on expired CRL data for head cert
    params.add(new Object[] {
            new ResourceCRLRevocationChecker(
                    new ClassPathResource[] { new ClassPathResource("userCA-expired.crl"),
                            new ClassPathResource("intermediateCA-valid.crl"),
                            new ClassPathResource("rootCA-valid.crl"), }),
            zeroThresholdPolicy,
            new String[] { "user-valid.crt", "userCA.crt", "intermediateCA.crt", "rootCA.crt" },
            new ExpiredCRLException("test", new Date()), });

    // Test case #4
    // Valid certificate on expired CRL data for intermediate cert
    params.add(new Object[] {
            new ResourceCRLRevocationChecker(
                    new ClassPathResource[] { new ClassPathResource("userCA-valid.crl"),
                            new ClassPathResource("intermediateCA-expired.crl"),
                            new ClassPathResource("rootCA-valid.crl"), }),
            zeroThresholdPolicy,
            new String[] { "user-valid.crt", "userCA.crt", "intermediateCA.crt", "rootCA.crt" },
            new ExpiredCRLException("test", new Date()), });

    // Test case #5
    // Valid certificate on expired CRL data with custom expiration
    // policy to always allow expired CRL data
    params.add(new Object[] {
            new ResourceCRLRevocationChecker(
                    new ClassPathResource[] { new ClassPathResource("userCA-expired.crl"), }),
            new RevocationPolicy<X509CRL>() {
                public void apply(X509CRL crl) {
                    /* Do nothing to allow unconditionally */}
            }, new String[] { "user-valid.crt" }, null, });

    return params;
}

From source file:fr.tse.fi2.hpp.labs.queries.impl.lab5.BloomFilterQuery.java

public boolean contain(String plaque, float loD, float laD, float loA, float laA) {
    String str = plaque + laA + loA + laD + loD;
    String[] str2hash = new String[k];

    MessageDigest md = null;/*from w w  w  . j av  a  2  s. co  m*/
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    for (int i = 0; i < 10; i++) {
        str2hash[i] = salt[i] + str;
        try {
            md.update(str2hash.toString().getBytes("UTF-16"));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        byte[] res = md.digest();
        BigInteger indiceB = new BigInteger(res);
        int indice = indiceB.intValue();

        if (indice < 0)
            indice = -indice;
        indice = indice % 14378;
        if (!bloomFilter.get(indice))
            return false;
    }
    return true;
}

From source file:com.mfizz.ruby.marshal.UnmarshalTest.java

@Test
public void unmarshalBignum() throws Exception {
    // ruby: Marshal.dump(12345678910111212333).unpack('H*')
    byte[] bytes = hextobytes("04086c2b092de335fc8ea954ab");
    RubyBignum rt = (RubyBignum) Marshal.load(bytes);
    Assert.assertEquals(new BigInteger("12345678910111212333"), rt.getValue());
}

From source file:com.appleframework.jmx.core.util.CoreUtils.java

public static Number valueOf(String value, String dataType) {
    if (dataType.equals("java.lang.Integer") || dataType.equals("int")) {
        return new Integer(value);
    }//w ww  .  ja  va  2 s .  co  m
    if (dataType.equals("java.lang.Double") || dataType.equals("double")) {
        return new Double(value);
    }
    if (dataType.equals("java.lang.Long") || dataType.equals("long")) {
        return new Long(value);
    }
    if (dataType.equals("java.lang.Float") || dataType.equals("float")) {
        return new Double(value);
    }
    if (dataType.equals("java.lang.Short") || dataType.equals("short")) {
        return new Short(value);
    }
    if (dataType.equals("java.lang.Byte") || dataType.equals("byte")) {
        return new Byte(value);
    }
    if (dataType.equals("java.math.BigInteger")) {
        return new BigInteger(value);
    }
    if (dataType.equals("java.math.BigDecimal")) {
        return new BigDecimal(value);
    }
    return null;
}

From source file:UInt64.java

/**
 * Create a UInt64 from a long./*from w w w.  j  a  v a2s  .c o m*/
 * 
 * @param value
 *          Must be a valid integer within MIN_VALUE&ndash;MAX_VALUE
 * @throws NumberFormatException
 *           if value is not between MIN_VALUE and MAX_VALUE
 */
public UInt64(long value) {
    //if ((value < MIN_VALUE) || (value > MAX_LONG_VALUE)) { throw new NumberFormatException(MessageFormat.format(
    //   _("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_LONG_VALUE })); }
    this.value = new BigInteger("" + value);
    top = this.value.shiftRight(32).and(new BigInteger("4294967295")).longValue();
    bottom = this.value.and(new BigInteger("4294967295")).longValue();
}

From source file:io.curly.advisor.model.Review.java

/**
 * Function to round up when the decimal part is more than a half, and down when its less than, if it is a half keep it
 *
 * @return fixed rate//from  w ww  .  j a  v  a 2  s.  com
 */
public BigDecimal fixPrecision() {
    if (rate == null)
        return null;
    BigDecimal decimal = rate.remainder(BigDecimal.ONE);
    BigInteger integer = rate.toBigInteger();
    if (decimal.compareTo(new BigDecimal(0.5)) > 0) {
        rate = new BigDecimal(integer.add(new BigInteger("1")));
    } else if (decimal.compareTo(new BigDecimal(0.5)) < 0) {
        rate = new BigDecimal(integer);
    }
    return rate;
}

From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.ranking.ProbabilityBased.java

/**
 * Constructor//from  w ww  . jav a 2 s .c  om
 * @param aFinder
 */
public ProbabilityBased(Finder aFinder) {
    super(aFinder);

    try {
        Properties properties = new Properties();
        BufferedInputStream stream = new BufferedInputStream(
                new FileInputStream("src/main/resources/index.properties"));
        properties.load(stream);
        stream.close();

        FREQUENCY = new BigInteger(properties.getProperty("frequency"));
    } catch (Exception e) {
        FREQUENCY = new BigInteger("143782944956");
    }
}

From source file:br.edimarmanica.fazenda.control.LoadBBControl.java

private boolean load(Pessoa pessoa, String file) {

    EntityManager em = Conexao.getEntityManager();
    em.getTransaction().begin();/*from  w  ww .j  a  v a 2  s.  co  m*/

    boolean error = false;

    try (CSVParser parser = CSVParser.parse(new File(file), Charset.forName("ISO-8859-1"),
            CSVFormat.EXCEL.withHeader())) {
        for (CSVRecord record : parser) {
            TipoCaixa tc = new TipoCaixa();
            tc.setCdBb(new BigInteger(record.get("Nmero do documento")));

            if (tc.getCdBb() != null) {
                List<TipoCaixa> tcs = daoTipo.search(tc);
                if (tcs != null && tcs.size() == 1) {
                    Caixa caixa = new Caixa();
                    caixa.setCdTipoCaixa(tcs.get(0));
                    caixa.setCdPessoa(pessoa);
                    caixa.setVlCaixa((new BigDecimal(record.get("Valor"))).abs());
                    caixa.setDtPagamento(new Date(record.get("Data")));
                    caixa.setDtVencimento(new Date(record.get("Data")));
                    caixa.setDsCaixa("IMPORTAO BB 02");
                    em.persist(caixa);
                }
            }

        }
    } catch (IOException ex) {
        Logger.getLogger(LoadBBControl.class.getName()).log(Level.SEVERE, null, ex);
        error = true;
    }

    if (!error) {
        em.getTransaction().commit();
    } else {
        em.getTransaction().rollback();
    }
    em.close();
    return !error;
}

From source file:org.jmangos.realm.network.packet.auth.client.CMD_AUTH_LOGON_CHALLENGE.java

@Override
protected void readImpl() throws BufferUnderflowException, RuntimeException {

    readC();/*from  w  ww .  j  a va 2 s.c o m*/
    if (readC() == WoWAuthResponse.WOW_SUCCESS.getMessageId()) {
        final SecureRandom random = new SecureRandom();
        MessageDigest sha = null;
        try {
            sha = MessageDigest.getInstance("SHA-1");
        } catch (final NoSuchAlgorithmException e) {
            e.printStackTrace();
            return;
        }
        final BigInteger k = new BigInteger("3");
        final byte[] Bb = readB(32);
        final BigInteger g = new BigInteger(readB(readC()));
        final byte[] Nb = readB(readC());
        final byte[] saltb = readB(32);
        /* byte[] unk3 = */readB(16);
        readC();
        ArrayUtils.reverse(Bb);
        final BigInteger B = new BigInteger(1, Bb);
        ArrayUtils.reverse(Bb);
        ArrayUtils.reverse(Nb);
        final BigInteger N = new BigInteger(1, Nb);
        ArrayUtils.reverse(Nb);
        final BigInteger a = new BigInteger(1, random.generateSeed(19));

        final byte[] passhash = sha.digest(this.config.AUTH_LOGIN.toUpperCase().concat(":")
                .concat(this.config.AUTH_PASSWORD.toUpperCase()).getBytes(Charset.forName("UTF-8")));
        sha.update(saltb);
        sha.update(passhash);

        final byte[] xhash = sha.digest();
        ArrayUtils.reverse(xhash);
        final BigInteger x = new BigInteger(1, xhash);
        logger.debug("x:" + x.toString(16).toUpperCase());
        final BigInteger v = g.modPow(x, N);
        logger.debug("v:" + v.toString(16).toUpperCase());
        final BigInteger A = g.modPow(a, N);
        logger.debug("A:" + A.toString(16).toUpperCase());
        logger.debug("B:" + B.toString(16).toUpperCase());
        this.ahash = A.toByteArray();
        ArrayUtils.reverse(this.ahash);
        sha.update(this.ahash);
        sha.update(Bb);
        final byte[] hashu = sha.digest();
        ArrayUtils.reverse(hashu);
        final BigInteger u = new BigInteger(1, hashu);
        logger.debug("u:" + u.toString(16).toUpperCase());
        final BigInteger S = (B.subtract(k.multiply(g.modPow(x, N)))).modPow(a.add(u.multiply(x)), N);

        final byte[] full_S = S.toByteArray();
        ArrayUtils.reverse(full_S);
        logger.debug("t:" + StringUtils.toHexString(full_S));
        final byte[] s1_hash = new byte[16];
        final byte[] s2_hash = new byte[16];
        for (int i = 0; i < 16; i++) {
            s1_hash[i] = full_S[i * 2];
            s2_hash[i] = full_S[(i * 2) + 1];
        }
        final byte[] t1 = sha.digest(s1_hash);
        final byte[] t2 = sha.digest(s2_hash);
        final byte[] vK = new byte[40];
        for (int i = 0; i < 20; i++) {
            vK[i * 2] = t1[i];
            vK[(i * 2) + 1] = t2[i];
        }

        byte[] hash = new byte[20];
        logger.debug("N:" + N.toString(16).toUpperCase());
        hash = sha.digest(Nb);

        logger.debug("hash:" + new BigInteger(1, hash).toString(16).toUpperCase());

        byte[] gH = new byte[20];
        sha.update(g.toByteArray());
        gH = sha.digest();
        for (int i = 0; i < 20; ++i) {
            hash[i] ^= gH[i];
        }

        byte[] t4 = new byte[20];
        t4 = sha.digest(this.config.AUTH_LOGIN.toUpperCase().getBytes(Charset.forName("UTF-8")));

        sha.update(hash);
        logger.debug("hash:" + StringUtils.toHexString(hash));
        sha.update(t4);
        logger.debug("t4:" + StringUtils.toHexString(t4));
        sha.update(saltb);
        logger.debug("saltb:" + StringUtils.toHexString(saltb));
        sha.update(this.ahash);
        logger.debug("ahash:" + StringUtils.toHexString(this.ahash));
        sha.update(Bb);
        logger.debug("Bb:" + StringUtils.toHexString(Bb));
        sha.update(vK);
        logger.debug("vK:" + StringUtils.toHexString(vK));
        this.m1 = sha.digest();

        sha.update(this.ahash);
        sha.update(this.m1);
        sha.update(vK);
        logger.debug("m1 value" + StringUtils.toHexString(this.m1));
        @SuppressWarnings("unused")
        final byte[] m2 = sha.digest();

        final ChannelPipeline pipeline = getClient().getChannel().getPipeline();
        ((RealmToAuthChannelHandler) pipeline.getLast()).setSeed(vK);

    } else {
        getChannel().getPipeline().remove("handler");
        getChannel().getPipeline().remove("eventlog");
        getChannel().getPipeline().remove("executor");
        getChannel().close();
        getChannel().getFactory().releaseExternalResources();
    }
}

From source file:dk.nsi.haiba.epimibaimporter.importer.ImportExecutorTest.java

@Test
public void answerSort() throws Exception {
    Answer a1 = new Answer();
    a1.setTransactionID(new BigInteger("1"));
    Answer a2 = new Answer();
    a2.setTransactionID(new BigInteger("2"));
    Answer a3 = new Answer();
    a3.setTransactionID(new BigInteger("3"));
    List<Answer> list = new ArrayList<Answer>();
    list.add(a3);/*  w w w.jav  a  2  s.c o m*/
    list.add(a2);
    list.add(a1);
    ImportExecutor.SortAnswersByTransactionIdComparator comp = new ImportExecutor.SortAnswersByTransactionIdComparator();
    Collections.sort(list, comp);
    assertTrue(list.get(0).getTransactionID().intValue() == 1);
    assertTrue(list.get(1).getTransactionID().intValue() == 2);
    assertTrue(list.get(2).getTransactionID().intValue() == 3);
}