Example usage for java.math BigInteger ZERO

List of usage examples for java.math BigInteger ZERO

Introduction

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

Prototype

BigInteger ZERO

To view the source code for java.math BigInteger ZERO.

Click Source Link

Document

The BigInteger constant zero.

Usage

From source file:eu.dety.burp.joseph.attacks.bleichenbacher_pkcs1.BleichenbacherPkcs1DecryptionAttackExecutor.java

private void stepThree(final int i) throws Exception {
    BigInteger n = this.pubKey.getModulus();
    BigInteger r;/*from w  ww . j  a v  a2  s .  c  o  m*/
    BigInteger upperBound;
    BigInteger lowerBound;
    BigInteger max;
    BigInteger min;
    BigInteger[] tmp;
    ArrayList<Interval> ms = new ArrayList<>(15);

    for (Interval interval : this.m) {
        upperBound = step3ComputeUpperBound(this.si, n, interval.upper);
        lowerBound = step3ComputeLowerBound(this.si, n, interval.lower);

        r = lowerBound;
        // lowerBound <= r <= upperBound
        while (r.compareTo(upperBound) < 1) {
            // ceil((2*B+r*n)/si)
            max = (BigInteger.valueOf(2).multiply(this.bigB)).add(r.multiply(n));
            tmp = max.divideAndRemainder(this.si);
            if (BigInteger.ZERO.compareTo(tmp[1]) != 0) {
                max = tmp[0].add(BigInteger.ONE);
            } else {
                max = tmp[0];
            }

            // floor((3*B-1+r*n)/si
            min = BigInteger.valueOf(3).multiply(this.bigB);
            min = min.subtract(BigInteger.ONE);
            min = min.add(r.multiply(n));
            min = min.divide(this.si);

            // build new interval
            if (interval.lower.compareTo(max) > 0) {
                max = interval.lower;
            }
            if (interval.upper.compareTo(min) < 0) {
                min = interval.upper;
            }
            if (max.compareTo(min) <= 0) {
                ms.add(new Interval(max, min));
            }
            // one further....
            r = r.add(BigInteger.ONE);
        }
    }

    loggerInstance.log(getClass(), " # of intervals for M" + i + ": " + ms.size(), Logger.LogLevel.INFO);

    if (ms.size() == 0) {
        throw new Exception("Zero intervals left, validity oracle seems to be wrong!");
    }

    this.m = ms.toArray(new Interval[ms.size()]);
}

From source file:org.mule.module.extension.internal.capability.xml.schema.SchemaBuilder.java

private void registerComplexTypeChildElement(ExplicitGroup all, String name, String description, DataType type,
        boolean required) {
    name = hyphenize(name);//from  w  w w .j a va2  s  .co m

    // this top level element is for declaring the object inside a config or operation
    TopLevelElement objectElement = new TopLevelElement();
    objectElement.setName(name);
    objectElement.setMinOccurs(required ? BigInteger.ONE : BigInteger.ZERO);
    objectElement.setMaxOccurs("1");
    objectElement.setComplexType(newLocalComplexTypeWithBase(type, description));
    objectElement.setAnnotation(createDocAnnotation(description));

    all.getParticle().add(objectFactory.createElement(objectElement));
}

From source file:org.multibit.utils.CSMiscUtils.java

@Deprecated
public static BigInteger calcRawPercentageCharge(CSAsset asset, BigInteger transferAmount) {
    CoinSparkGenesis genesis = asset.getGenesis();
    int chargeBasisPoints = genesis.getChargeBasisPoints();
    if (chargeBasisPoints == 0)
        return BigInteger.ZERO;
    BigDecimal d = new BigDecimal(chargeBasisPoints);
    d = d.movePointLeft(2 + 2); // 2 to get whole percent number, another 2 to get fraction
    d = d.multiply(new BigDecimal(transferAmount), MathContext.UNLIMITED);
    return d.toBigInteger();
}

From source file:co.rsk.blockchain.utils.BlockGenerator.java

public static Block createEmptyGenesisBlock() {
    Bloom logBloom = new Bloom();
    Block original = BlockGenerator.getGenesisBlock();

    return new Block(original.getParentHash(), // parent hash
            EMPTY_LIST_HASH, // uncle hash
            original.getCoinbase(), // coinbase
            logBloom.getData(), // logs bloom
            original.getDifficulty(), // difficulty
            0, original.getGasLimit(), original.getGasUsed(), original.getTimestamp() + ++count,
            EMPTY_BYTE_ARRAY, // extraData
            EMPTY_BYTE_ARRAY, // mixHash
            BigInteger.ZERO.toByteArray(), // provisory nonce
            EMPTY_TRIE_HASH, // receipts root
            EMPTY_TRIE_HASH, // transaction receipts
            EMPTY_TRIE_HASH, // state root
            null, // transaction list
            null, // uncle list
            BigInteger.valueOf(RskSystemProperties.RSKCONFIG.minerMinGasPrice()).toByteArray());
}

From source file:edu.vt.cs.cnd2xsd.Cnd2XsdConverter.java

private void convert(OutputStream stream) {
    OutputStream fout = stream;//from  w ww  .j  av a 2  s  .c o m
    try {

        SchemaElement schemaRoot = new SchemaElement();

        schemaRoot.setElementFormDefault(FormChoice.QUALIFIED);
        schemaRoot.setTargetNamespace(this.namespace);
        JAXBContext jc = JAXBContext.newInstance(SchemaElement.class);
        Marshaller m = jc.createMarshaller();
        List<OpenAttrs> rootAttrList = schemaRoot.getIncludesAndImportsAndRedefines();
        ElementElement rootElement = new ElementElement();
        QName qname = new QName(this.namespace, this.rootType);
        rootElement.setType(qname);
        rootElement.setName(this.root);
        rootAttrList.add(rootElement);

        //the first level nodes that are children of rsrRoot are those nodes that
        //do not have any parent nodes in the cnd.

        for (NodeType nt : ntypes) {

            log.debug("NodeType:" + nt.getName());

            //check if we already have that node - if we have then update it

            QName name = getQualifiedName(nt.getName());

            ComplexTypeElement ctype = (ComplexTypeElement) getComplexType(rootAttrList, name.getLocalPart(),
                    attrMap.containsKey(nt.getName()) ? attrMap.get(nt.getName()) : null);

            for (NodeType pt : nt.getDeclaredSupertypes()) {
                log.debug("  DeclaredSuperType:" + pt.getName());
                //based on the supertypes we will have to make decisions
                if (attrMap.containsKey(pt.getName())) {
                    //check if we have to create a node
                    String[] attrs = attrMap.get(pt.getName());
                    if (attrs != null) {
                        //get the qualified name
                        QName ename = getQualifiedName(pt.getName());
                        //create a complex type
                        //check if the complex type already there in the rootAttrList
                        ComplexType ctf = findComplexType(rootAttrList, ename.getLocalPart());

                        if (ctf == null) {
                            ctf = new ComplexTypeElement();
                            ctf.setName(ename.getLocalPart());
                            //add the attributes
                            for (String attr : attrs) {
                                Attribute attribute = new Attribute();
                                QName type = new QName(Constants.XML_NAMESPACE, Constants.STRING);
                                attribute.setType(type);
                                attribute.setName(attr);
                                ctf.getAttributesAndAttributeGroups().add(attribute);
                            }

                            //add this complex type to the attribute list of the root element
                            rootAttrList.add(ctf);
                        }

                        //create an element of the above complex type and add as element
                        ElementElement element = new ElementElement();
                        element.setName(ename.getLocalPart());
                        element.setType(new QName(this.namespace, ctf.getName()));
                        element.setMinOccurs(BigInteger.ONE);
                        element.setMaxOccurs("1");
                        //element.setType(new QName(ctf.));
                        //now add this element to the top level complex type's sequence
                        ctype.getSequence().getElementsAndGroupsAndAlls().add(element);

                    }
                }
                //the supertype is not a pre-define type - we then have to add it as an element
                else {

                    QName qn = getQualifiedName(pt.getName());
                    ComplexType ctf = getComplexType(rootAttrList, qn.getLocalPart(),
                            attrMap.containsKey(nt.getName()) ? attrMap.get(nt.getName()) : null);

                    //create an element of the above type and add as element
                    ElementElement element = new ElementElement();
                    element.setName(qn.getLocalPart());
                    element.setType(new QName(this.namespace, ctf.getName()));
                    element.setMinOccurs(BigInteger.ONE);
                    element.setMaxOccurs("1");

                    //element.setType(new QName(ctf.));
                    //now add this element to the top level complex type's sequence
                    ctype.getSequence().getElementsAndGroupsAndAlls().add(element);

                }
            }

            for (NodeDefinition nd : nt.getDeclaredChildNodeDefinitions()) {
                log.debug("  Declared ChildNode Definition:" + nd.getName());
                //check default primary type
                NodeType defaultNT = nd.getDefaultPrimaryType();
                if (defaultNT == null) {
                    log.debug("Default Primary Type for the node:" + nd.getName() + " is null");
                    //look for the primary type
                    NodeType[] nts = nd.getRequiredPrimaryTypes();
                    if (ntypes == null) {
                        log.debug("No required primary type for node:" + nd.getName());
                    } else {
                        defaultNT = nts[0];
                        log.debug("Assuming first primary  type:" + defaultNT.getName() + " for node:"
                                + nd.getName());
                    }

                }
                log.debug("  Default Primary Type Name:" + defaultNT.getName());
                ElementElement element = new ElementElement();
                if (nd.getName().equals("*")) {
                    QName qn = getQualifiedName(defaultNT.getName());
                    ComplexType ct = getComplexType(rootAttrList, qn.getLocalPart(),
                            attrMap.containsKey(nt.getName()) ? attrMap.get(nt.getName()) : null);

                    //QName ename = getQualifiedName(ct.getName());
                    element.setName(ct.getName());
                    element.setType(new QName(this.namespace, ct.getName()));
                    element.setMinOccurs(nd.isMandatory() ? BigInteger.ONE : BigInteger.ZERO);
                    //add an attribute called nodename so that it can be used to identify the node
                    QName type = new QName(Constants.XML_NAMESPACE, Constants.STRING);
                    Attribute attribute = new Attribute();
                    attribute.setType(type);
                    attribute.setName("nodename");
                    ct.getAttributesAndAttributeGroups().add(attribute);

                    if (nd.allowsSameNameSiblings()) {
                        element.setMaxOccurs(Constants.UNBOUNDED);
                    }

                } else {

                    QName qn = getQualifiedName(defaultNT.getName());
                    ComplexType ct = getComplexType(rootAttrList, qn.getLocalPart(),
                            attrMap.containsKey(nt.getName()) ? attrMap.get(nt.getName()) : null);

                    QName ename = getQualifiedName(nd.getName());
                    element.setName(ename.getLocalPart());
                    element.setType(new QName(this.namespace, ct.getName()));
                    element.setMinOccurs(nd.isMandatory() ? BigInteger.ONE : BigInteger.ZERO);

                    if (nd.allowsSameNameSiblings()) {
                        element.setMaxOccurs(Constants.UNBOUNDED);
                    }

                }
                ctype.getSequence().getElementsAndGroupsAndAlls().add(element);

            }

            for (PropertyDefinition pDef : nt.getPropertyDefinitions()) {
                log.debug("    Attr Name:" + pDef.getName());
                log.debug("    Req type:" + pDef.getRequiredType());
                log.debug("    Declaring Node type:" + pDef.getDeclaringNodeType().getName());
                if (pDef.getDeclaringNodeType().getName().equals(nt.getName())) {

                    QName qn = getQualifiedName(pDef.getName());
                    if (!pDef.isMultiple()) {
                        Attribute attr = new Attribute();
                        if (isUnsupportedType(pDef.getRequiredType())) {
                            attr.setType(new QName(Constants.XML_NAMESPACE, Constants.STRING));

                        } else {
                            attr.setType(new QName(Constants.XML_NAMESPACE,
                                    PropertyType.nameFromValue(pDef.getRequiredType()).toLowerCase()));
                        }
                        attr.setName(qn.getLocalPart());
                        //handle default value
                        Value[] defaultValues = pDef.getDefaultValues();
                        if (defaultValues != null && defaultValues.length > 0) {
                            attr.setDefault(defaultValues[0].getString());
                        }

                        ctype.getAttributesAndAttributeGroups().add(attr);
                    } else {
                        ComplexType ctf = getComplexType(rootAttrList, qn.getLocalPart(),
                                attrMap.containsKey(nt.getName()) ? attrMap.get(nt.getName()) : null);
                        if (ctf != null) {
                            ElementElement element = new ElementElement();
                            element.setName(qn.getLocalPart());
                            element.setMinOccurs(BigInteger.ZERO);
                            element.setMaxOccurs(Constants.UNBOUNDED);
                            if (isUnsupportedType(pDef.getRequiredType())) {
                                element.setType(new QName(Constants.XML_NAMESPACE, Constants.STRING));

                            } else {
                                element.setType(new QName(Constants.XML_NAMESPACE,
                                        PropertyType.nameFromValue(pDef.getRequiredType()).toLowerCase()));
                            }
                            ctf.getSequence().getElementsAndGroupsAndAlls().add(element);

                        }

                        //now create an element of the above type
                        ElementElement element = new ElementElement();
                        element.setName(qn.getLocalPart());
                        element.setType(new QName(this.namespace, ctf.getName()));
                        ctype.getSequence().getElementsAndGroupsAndAlls().add(element);

                    }

                }

            }

        }
        //decide what to put under rootNode

        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        //fout = new FileOutputStream(fileName);
        m.marshal(schemaRoot, fout);

    } catch (Exception ex) {
        log.debug("Exception:" + ex.getMessage());
        ex.printStackTrace();
    } finally {
        if (fout != null) {
            try {
                fout.close();
            } catch (IOException ex) {
                log.error("Exception caught: {}", ex.getMessage());
            }
        }
    }

}

From source file:org.qi4j.runtime.value.CollectionTypeTest.java

private Collection<BigInteger> bigIntegerCollection() {
    Collection<BigInteger> value = new ArrayList<BigInteger>();
    value.add(new BigInteger("-1"));
    value.add(BigInteger.ZERO);
    value.add(BigInteger.ONE);/* w  w  w  .ja  v  a 2 s  .  c  om*/
    value.add(null);
    value.add(BigInteger.TEN);
    value.add(new BigInteger("-1827368263823729372397239829332"));
    value.add(new BigInteger("2398723982982379827373972398723"));
    return value;
}

From source file:org.multibit.utils.CSMiscUtils.java

@Deprecated
public static BigInteger calcRawFlatCharge(CSAsset asset) {
    CoinSparkGenesis genesis = asset.getGenesis();
    short chargeExponent = genesis.getChargeFlatExponent();
    short chargeMantissa = genesis.getChargeFlatMantissa();
    if (0 == chargeMantissa)
        return BigInteger.ZERO;
    BigInteger n = new BigInteger("10").pow(chargeExponent);
    n = n.multiply(new BigInteger(String.valueOf(chargeMantissa)));
    return n;//from ww w . j av a 2 s.c  o m
}

From source file:eu.dety.burp.joseph.attacks.bleichenbacher_pkcs1.BleichenbacherPkcs1DecryptionAttackExecutor.java

private BigInteger step3ComputeUpperBound(final BigInteger s, final BigInteger modulus,
        final BigInteger upperIntervalBound) {
    BigInteger upperBound = upperIntervalBound.multiply(s);
    upperBound = upperBound.subtract(BigInteger.valueOf(2).multiply(bigB));
    // ceil//from  w w w .  j  a  v a  2 s. c om
    BigInteger[] tmp = upperBound.divideAndRemainder(modulus);
    if (BigInteger.ZERO.compareTo(tmp[1]) != 0) {
        upperBound = BigInteger.ONE.add(tmp[0]);
    } else {
        upperBound = tmp[0];
    }

    return upperBound;
}

From source file:co.rsk.blockchain.utils.BlockGenerator.java

public static Block createSimpleChildBlock(Block parent, int ntxs) {
    Bloom logBloom = new Bloom();

    List<Transaction> txs = new ArrayList<>();

    for (int ntx = 0; ntx < ntxs; ntx++)
        txs.add(new SimpleRskTransaction(PegTestUtils.createHash3().getBytes()));

    return new SimpleBlock(parent.getHash(), // parent hash
            EMPTY_LIST_HASH, // uncle hash
            parent.getCoinbase(), // coinbase
            logBloom.getData(), // logs bloom
            parent.getDifficulty(), // difficulty
            parent.getNumber() + 1, parent.getGasLimit(), parent.getGasUsed(), parent.getTimestamp() + ++count,
            EMPTY_BYTE_ARRAY, // extraData
            EMPTY_BYTE_ARRAY, // mixHash
            BigInteger.ZERO.toByteArray(), // provisory nonce
            EMPTY_TRIE_HASH, // receipts root
            EMPTY_TRIE_HASH, // transaction receipts
            EMPTY_TRIE_HASH, // state root
            txs, // transaction list
            null // uncle list
    );/*from www  .ja va2 s .com*/
}

From source file:piuk.blockchain.android.MyRemoteWallet.java

public void parseMultiAddr(String response, boolean notifications) throws Exception {

    transactions.clear();/*from   w ww .jav  a 2s .  c o  m*/

    BigInteger previousBalance = final_balance;

    Map<String, Object> top = (Map<String, Object>) JSONValue.parse(response);

    this.multiAddrRoot = (JSONObject) top;

    Map<String, Object> info_obj = (Map<String, Object>) top.get("info");

    Map<String, Object> block_obj = (Map<String, Object>) info_obj.get("latest_block");

    if (block_obj != null) {
        Sha256Hash hash = new Sha256Hash(Hex.decode((String) block_obj.get("hash")));
        int blockIndex = ((Number) block_obj.get("block_index")).intValue();
        int blockHeight = ((Number) block_obj.get("height")).intValue();
        long time = ((Number) block_obj.get("time")).longValue();

        MyBlock block = new MyBlock();

        block.height = blockHeight;
        block.hash = hash;
        block.blockIndex = blockIndex;
        block.time = time;

        this.latestBlock = block;
    }

    List<JSONObject> multiAddrBalances = (List<JSONObject>) top.get("addresses");

    Map<String, JSONObject> multiAddrBalancesRoot = new HashMap<String, JSONObject>();

    for (JSONObject obj : multiAddrBalances) {
        multiAddrBalancesRoot.put((String) obj.get("address"), obj);
    }

    this.multiAddrBalancesRoot = multiAddrBalancesRoot;

    Map<String, Object> symbol_local = (Map<String, Object>) info_obj.get("symbol_local");

    boolean didUpdateCurrency = false;

    if (symbol_local != null && symbol_local.containsKey("code")) {
        String currencyCode = (String) symbol_local.get("code");
        Double currencyConversion = (Double) symbol_local.get("conversion");

        if (currencyConversion == null)
            currencyConversion = 0d;

        if (this.localCurrencyCode == null || !this.localCurrencyCode.equals(currencyCode)
                || this.localCurrencyConversion != currencyConversion) {
            this.localCurrencyCode = currencyCode;
            this.localCurrencyConversion = currencyConversion;
            didUpdateCurrency = true;
        }
    }

    Map<String, Object> symbol_btc = (Map<String, Object>) info_obj.get("symbol_btc");
    if (symbol_btc != null && symbol_btc.containsKey("code")) {
        String currencyCode = (String) symbol_local.get("code");
        Double currencyConversion = (Double) symbol_local.get("conversion");

        if (currencyConversion == null)
            currencyConversion = 0d;

        if (this.btcCurrencyCode == null || !this.btcCurrencyCode.equals(currencyCode)
                || this.btcCurrencyConversion != currencyConversion) {
            this.btcCurrencyCode = currencyCode;
            this.btcCurrencyConversion = currencyConversion;
            //didUpdateCurrency = true;
        }
    }

    if (didUpdateCurrency) {
        EventListeners.invokeCurrencyDidChange();
    }

    if (top.containsKey("mixer_fee")) {
        sharedFee = ((Number) top.get("mixer_fee")).doubleValue();
    }

    Map<String, Object> wallet_obj = (Map<String, Object>) top.get("wallet");

    this.final_balance = BigInteger.valueOf(((Number) wallet_obj.get("final_balance")).longValue());
    this.total_sent = BigInteger.valueOf(((Number) wallet_obj.get("total_sent")).longValue());
    this.total_received = BigInteger.valueOf(((Number) wallet_obj.get("total_received")).longValue());

    List<Map<String, Object>> transactions = (List<Map<String, Object>>) top.get("txs");

    MyTransaction newestTransaction = null;
    if (transactions != null) {
        for (Map<String, Object> transactionDict : transactions) {
            MyTransaction tx = MyTransaction.fromJSONDict(transactionDict);

            if (tx == null)
                continue;

            if (newestTransaction == null)
                newestTransaction = tx;

            addTransaction(tx);
        }
    }

    if (notifications) {
        if (this.final_balance.compareTo(previousBalance) != 0 && newestTransaction != null) {
            if (newestTransaction.getResult().compareTo(BigInteger.ZERO) >= 0)
                EventListeners.invokeOnCoinsReceived(newestTransaction,
                        newestTransaction.getResult().longValue());
            else
                EventListeners.invokeOnCoinsSent(newestTransaction, newestTransaction.getResult().longValue());
        }
    } else {
        EventListeners.invokeOnTransactionsChanged();
    }
}