List of usage examples for java.math BigInteger ONE
BigInteger ONE
To view the source code for java.math BigInteger ONE.
Click Source Link
From source file:org.owasp.jbrofuzz.core.FuzzerBigInteger.java
/** * <p>Return the next element of the fuzzer during iteration.</p> * //from w w w . j a v a 2s . c o m * <p>This method should be used to access fuzzing payloads, after * construction of the fuzzer object.</p> * * @return String The next fuzzer payload, during the iteration * process * * @author subere@uncon.org * @version 2.4 * @since 1.2 */ public String next() { final StringBuffer output = new StringBuffer(""); // Replacive Prototype if (maxValue.compareTo(BigInteger.valueOf(payloads.size())) == 0) { output.append(payloads.get(cValue.intValue())); cValue = cValue.add(BigInteger.ONE); } // Recursive Prototype else { BigInteger val = cValue; // Perform division on a stack final Stack<BigInteger> stack = new Stack<BigInteger>(); while (val.compareTo(BigInteger.valueOf(payloads.size())) >= 0) { stack.push(val.mod(BigInteger.valueOf(payloads.size()))); val = val.divide(BigInteger.valueOf(payloads.size())); } // Append the relevant empty positions with the first element // identified output.append(StringUtils.leftPad(payloads.get(val.intValue()), len - stack.size(), payloads.get(0))); while (!stack.isEmpty()) { output.append(payloads.get(stack.pop().intValue())); } cValue = cValue.add(BigInteger.ONE); } return output.toString(); }
From source file:io.vertx.config.vault.utils.Certificates.java
/** * See http://www.programcreek.com/java-api-examples/index.php?api=org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder * * @param keyPair The RSA keypair with which to generate the certificate * @param issuer The issuer (and subject) to use for the certificate * @return An X509 certificate// w w w . j a va2 s .c om * @throws IOException * @throws OperatorCreationException * @throws CertificateException * @throws NoSuchProviderException * @throws NoSuchAlgorithmException * @throws InvalidKeyException * @throws SignatureException */ private static X509Certificate generateCert(final KeyPair keyPair, final String issuer) throws IOException, OperatorCreationException, CertificateException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { final String subject = issuer; final X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(new X500Name(issuer), BigInteger.ONE, new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30), new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 30)), new X500Name(subject), SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded())); final GeneralNames subjectAltNames = new GeneralNames(new GeneralName(GeneralName.iPAddress, "127.0.0.1")); certificateBuilder.addExtension(org.bouncycastle.asn1.x509.Extension.subjectAlternativeName, false, subjectAltNames); final AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder() .find("SHA1WithRSAEncryption"); final AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId); final BcContentSignerBuilder signerBuilder = new BcRSAContentSignerBuilder(sigAlgId, digAlgId); final AsymmetricKeyParameter keyp = PrivateKeyFactory.createKey(keyPair.getPrivate().getEncoded()); final ContentSigner signer = signerBuilder.build(keyp); final X509CertificateHolder x509CertificateHolder = certificateBuilder.build(signer); final X509Certificate certificate = new JcaX509CertificateConverter().getCertificate(x509CertificateHolder); certificate.checkValidity(new Date()); certificate.verify(keyPair.getPublic()); return certificate; }
From source file:com.spotify.reaper.unit.service.SegmentRunnerTest.java
@Test public void successTest() throws InterruptedException, ReaperException, ExecutionException { final IStorage storage = new MemoryStorage(); RepairUnit cf = storage/* w w w . j a v a 2 s .com*/ .addRepairUnit(new RepairUnit.Builder("reaper", "reaper", Sets.newHashSet("reaper"))); RepairRun run = storage.addRepairRun( new RepairRun.Builder("reaper", cf.getId(), DateTime.now(), 0.5, 1, RepairParallelism.PARALLEL)); storage.addRepairSegments(Collections.singleton( new RepairSegment.Builder(run.getId(), new RingRange(BigInteger.ONE, BigInteger.ZERO), cf.getId())), run.getId()); final long segmentId = storage.getNextFreeSegment(run.getId()).get().getId(); final ExecutorService executor = Executors.newSingleThreadExecutor(); final MutableObject<Future<?>> future = new MutableObject<>(); AppContext context = new AppContext(); context.storage = storage; context.jmxConnectionFactory = new JmxConnectionFactory() { @Override public JmxProxy connect(final Optional<RepairStatusHandler> handler, String host) { JmxProxy jmx = mock(JmxProxy.class); when(jmx.getClusterName()).thenReturn("reaper"); when(jmx.isConnectionAlive()).thenReturn(true); when(jmx.tokenRangeToEndpoint(anyString(), any(RingRange.class))) .thenReturn(Lists.newArrayList("")); when(jmx.triggerRepair(any(BigInteger.class), any(BigInteger.class), anyString(), Matchers.<RepairParallelism>any(), Sets.newHashSet(anyString()))) .then(new Answer<Integer>() { @Override public Integer answer(InvocationOnMock invocation) { assertEquals(RepairSegment.State.NOT_STARTED, storage.getRepairSegment(segmentId).get().getState()); future.setValue(executor.submit(new Runnable() { @Override public void run() { handler.get().handle(1, ActiveRepairService.Status.STARTED, "Repair command 1 has started"); assertEquals(RepairSegment.State.RUNNING, storage.getRepairSegment(segmentId).get().getState()); // report about an unrelated repair. Shouldn't affect anything. handler.get().handle(2, ActiveRepairService.Status.SESSION_FAILED, "Repair command 2 has failed"); handler.get().handle(1, ActiveRepairService.Status.SESSION_SUCCESS, "Repair session succeeded in command 1"); assertEquals(RepairSegment.State.DONE, storage.getRepairSegment(segmentId).get().getState()); handler.get().handle(1, ActiveRepairService.Status.FINISHED, "Repair command 1 has finished"); assertEquals(RepairSegment.State.DONE, storage.getRepairSegment(segmentId).get().getState()); } })); return 1; } }); return jmx; } }; RepairRunner rr = mock(RepairRunner.class); RepairUnit ru = mock(RepairUnit.class); SegmentRunner sr = new SegmentRunner(context, segmentId, Collections.singleton(""), 1000, 0.5, RepairParallelism.PARALLEL, "reaper", ru, rr); sr.run(); future.getValue().get(); executor.shutdown(); assertEquals(RepairSegment.State.DONE, storage.getRepairSegment(segmentId).get().getState()); assertEquals(0, storage.getRepairSegment(segmentId).get().getFailCount()); }
From source file:strat.mining.stratum.proxy.worker.GetworkJobTemplate.java
public GetworkJobTemplate(GetworkJobTemplate toClone) { this.jobId = toClone.jobId; this.merkleBranches = new ArrayList<String>(toClone.merkleBranches); this.coinbase1 = toClone.coinbase1; this.coinbase2 = toClone.coinbase2; this.extranonce1 = toClone.extranonce1; this.hashPrevBlock = toClone.hashPrevBlock; this.version = toClone.version; // Create the time BigInteger from the LittleEndian hex data. this.time = new AtomicBigInteger(toClone.time); this.bits = toClone.bits; this.nonce = toClone.nonce; this.lastDataTemplateUpdateTime = toClone.lastDataTemplateUpdateTime; this.target = DEFAULT_TARGET; this.targetInteger = BigInteger.ONE; this.noMidState = toClone.noMidState; computeTemplateData();/* www .j a v a2 s . c om*/ }
From source file:com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesServiceTest.java
/** * Test method for {@link com.github.jrrdev.mantisbtsync.core.services.JdbcIssuesService#insertPriorityIfNotExists(biz.futureware.mantis.rpc.soap.client.ObjectRef)}. *///from w w w . ja v a2s. c om @Test public void testInsertPriorityIfNotExists() { final ObjectRef item = new ObjectRef(BigInteger.ONE, "item"); final boolean result = dao.insertPriorityIfNotExists(item); assertTrue(result); final List<ObjectRef> list = getJdbcTemplate().query("SELECT id, name FROM mantis_enum_priorities", new BeanPropertyRowMapper<ObjectRef>(ObjectRef.class)); assertEquals(1, list.size()); assertEquals(item, list.get(0)); final boolean result2 = dao.insertPriorityIfNotExists(item); assertTrue(result2); }
From source file:gedi.util.math.stat.distributions.OccupancyNumberDistribution.java
private static final BigInteger factorial(int b) { if (b == 0)//from w w w. j av a 2 s . c o m return BigInteger.ONE; BigInteger re = BigInteger.valueOf(b); for (int i = b - 1; i > 1; i--) re = re.multiply(BigInteger.valueOf(i)); return re; }
From source file:com.otterca.common.crypto.acceptance.X509CertificateBuilderAcceptanceTest.java
/** * Populate a builder with standard values used in testing. * /*from ww w . ja va 2 s. com*/ * @param builder */ public void populate(X509CertificateBuilder builder) { serial = serial.add(BigInteger.ONE); builder.setSerialNumber(serial); builder.setSubject(SUBJECT_NAME); builder.setIssuer(SUBJECT_NAME); builder.setNotBefore(notBefore.getTime()); builder.setNotAfter(notAfter.getTime()); builder.setPublicKey(keyPair.getPublic()); }
From source file:cc.redberry.core.number.Rational.java
@Override public String toString() { return fraction.getNumerator().toString() + (fraction.getDenominator().equals(BigInteger.ONE) ? "" : ("/" + fraction.getDenominator().toString())); }
From source file:eu.dety.burp.joseph.attacks.bleichenbacher_pkcs1.BleichenbacherPkcs1DecryptionAttackExecutor.java
private void stepOne() throws Exception { byte[] send;/*from w w w . ja v a 2 s . c o m*/ IHttpRequestResponse response; byte[] request; BigInteger ciphered = new BigInteger(1, this.encryptedKey); do { // Check if user has cancelled the worker if (isCancelled()) { loggerInstance.log(getClass(), "Decryption Attack Executor Worker cancelled by user", Logger.LogLevel.INFO); return; } this.si = this.si.add(BigInteger.ONE); send = prepareMsg(ciphered, this.si); request = this.requestResponse.getRequest(); String[] components = Decoder.getComponents(this.parameter.getJoseValue()); components[1] = Decoder.base64UrlEncode(send); String newComponentsConcatenated = Decoder.concatComponents(components); request = JoseParameter.updateRequest(request, this.parameter, helpers, newComponentsConcatenated); response = callbacks.makeHttpRequest(this.httpService, request); updateAmountRequest(); } while (oracle.getResult(response.getResponse()) != BleichenbacherPkcs1Oracle.Result.VALID); this.c0 = new BigInteger(1, send); this.s0 = this.si; // mi = {[2B,3B-1]} this.m = new Interval[] { new Interval(BigInteger.valueOf(2).multiply(bigB), (BigInteger.valueOf(3).multiply(bigB)).subtract(BigInteger.ONE)) }; loggerInstance.log(getClass(), "Found s0 : " + this.si, Logger.LogLevel.INFO); }
From source file:com.stratio.ingestion.sink.cassandra.EventParserTest.java
@Test public void shouldParsePrimitiveTypes() throws Exception { Object integer = EventParser.parseValue("1", DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(1); integer = EventParser.parseValue(Integer.toString(Integer.MAX_VALUE), DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(Integer.MAX_VALUE); integer = EventParser.parseValue(Integer.toString(Integer.MIN_VALUE), DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(Integer.MIN_VALUE); integer = EventParser.parseValue(" 1 2 ", DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(12); Object counter = EventParser.parseValue("1", DataType.Name.COUNTER); assertThat(counter).isEqualTo(1L);//from www .j a v a2s . c om counter = EventParser.parseValue(Long.toString(Long.MAX_VALUE), DataType.Name.COUNTER); assertThat(counter).isEqualTo(Long.MAX_VALUE); counter = EventParser.parseValue(Long.toString(Long.MIN_VALUE), DataType.Name.COUNTER); assertThat(counter).isEqualTo(Long.MIN_VALUE); counter = EventParser.parseValue(" 1 2 ", DataType.Name.COUNTER); assertThat(counter).isEqualTo(12L); Object _float = EventParser.parseValue("1", DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f); _float = EventParser.parseValue("1.0", DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f); _float = EventParser.parseValue(Float.toString(Float.MAX_VALUE), DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(Float.MAX_VALUE); _float = EventParser.parseValue(Float.toString(Float.MIN_VALUE), DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(Float.MIN_VALUE); _float = EventParser.parseValue(" 1 . 0 ", DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f); Object _double = EventParser.parseValue("1", DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(1.0); _double = EventParser.parseValue("0", DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(0.0); _double = EventParser.parseValue(Double.toString(Double.MAX_VALUE), DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(Double.MAX_VALUE); _double = EventParser.parseValue(Double.toString(Double.MIN_VALUE), DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(Double.MIN_VALUE); _double = EventParser.parseValue(" 1 . 0 ", DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(1.0); for (DataType.Name type : Arrays.asList(DataType.Name.BIGINT)) { Object bigInteger = EventParser.parseValue("1", type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(1L); bigInteger = EventParser.parseValue("0", type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(0L); bigInteger = EventParser.parseValue(Long.toString(Long.MAX_VALUE), type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(Long.MAX_VALUE); bigInteger = EventParser.parseValue(Long.toString(Long.MIN_VALUE), type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(Long.MIN_VALUE); } for (DataType.Name type : Arrays.asList(DataType.Name.VARINT)) { Object bigInteger = EventParser.parseValue("1", type); assertThat(bigInteger).isInstanceOf(BigInteger.class).isEqualTo(BigInteger.ONE); bigInteger = EventParser.parseValue("0", type); assertThat(bigInteger).isInstanceOf(BigInteger.class).isEqualTo(BigInteger.ZERO); bigInteger = EventParser.parseValue( BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2L)).toString(), type); assertThat(bigInteger).isInstanceOf(BigInteger.class) .isEqualTo(BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2L))); bigInteger = EventParser.parseValue( BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.valueOf(2L)).toString(), type); assertThat(bigInteger).isInstanceOf(BigInteger.class) .isEqualTo(BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.valueOf(2L))); } Object bigDecimal = EventParser.parseValue("1", DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(1)); bigDecimal = EventParser.parseValue("0", DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(0)); bigDecimal = EventParser.parseValue( BigDecimal.valueOf(Double.MAX_VALUE).multiply(BigDecimal.valueOf(2)).toString(), DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class) .isEqualTo(BigDecimal.valueOf(Double.MAX_VALUE).multiply(BigDecimal.valueOf(2))); bigDecimal = EventParser.parseValue( BigDecimal.valueOf(Double.MIN_VALUE).multiply(BigDecimal.valueOf(2)).toString(), DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class) .isEqualTo(BigDecimal.valueOf(Double.MIN_VALUE).multiply(BigDecimal.valueOf(2))); bigDecimal = EventParser.parseValue(" 1 2 ", DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(12)); Object string = EventParser.parseValue("string", DataType.Name.TEXT); assertThat(string).isInstanceOf(String.class).isEqualTo("string"); Object bool = EventParser.parseValue("true", DataType.Name.BOOLEAN); assertThat(bool).isInstanceOf(Boolean.class).isEqualTo(true); Object addr = EventParser.parseValue("192.168.1.1", DataType.Name.INET); assertThat(addr).isInstanceOf(InetAddress.class).isEqualTo(InetAddress.getByName("192.168.1.1")); UUID randomUUID = UUID.randomUUID(); Object uuid = EventParser.parseValue(randomUUID.toString(), DataType.Name.UUID); assertThat(uuid).isInstanceOf(UUID.class).isEqualTo(randomUUID); }