List of usage examples for java.math BigInteger BigInteger
private BigInteger(long val)
From source file:Main.java
public static String validateAndFixUserPhoneNumber(String text) { try {/* w w w . jav a 2 s .com*/ text = text.trim(); if (text.charAt(0) == '+') { text = text.substring(1); } BigInteger dummy = new BigInteger(text); if (text.charAt(0) == '8') { StringBuilder strBuilder = new StringBuilder(text); strBuilder.setCharAt(0, '7'); text = strBuilder.toString(); } if (text.charAt(0) != '7' || text.length() != 11) { throw new Exception(); } text = "+" + text; } catch (Throwable t) { text = ""; //LOGE("validateAndFixUserPhoneNumber: " + t.getMessage()); t.printStackTrace(); } return text; }
From source file:Main.java
public static String BytesToBase58(byte[] value) { //Add 1 for each 00 byte. //From lowest base58 fill with division remainders. String returnValue = ""; boolean justStarted = true; BigInteger bigValue = new BigInteger(value); //TODO: Check that it works as it should. BigInteger base58 = new BigInteger("58"); BigInteger zero = new BigInteger("0"); BigInteger[] divisionResult;/* w w w .j a v a 2 s. c o m*/ while (bigValue.compareTo(zero) == 1) { //Means greater than. divisionResult = bigValue.divideAndRemainder(base58); bigValue = divisionResult[0]; returnValue = base58Array.toCharArray()[divisionResult[1].intValue()] + returnValue; } for (int i = 0; i < value.length; i++) { if (value[i] == 0 && justStarted) { returnValue = "1" + returnValue; } else { break; } justStarted = false; } return returnValue; }
From source file:Main.java
/** * Converts a little endian byte array to a BigInteger. * * @param bytes The bytes to convert./*w w w .j a v a 2 s . com*/ * @return The resulting BigInteger. */ public static BigInteger toBigInteger(final byte[] bytes) { final byte[] bigEndianBytes = new byte[bytes.length + 1]; for (int i = 0; i < bytes.length; ++i) { bigEndianBytes[i + 1] = bytes[bytes.length - i - 1]; } return new BigInteger(bigEndianBytes); }
From source file:Main.java
public static String convertPhoneNumberTo8Format(String text) { try {//from w w w . j a v a2s. com text = text.trim(); if (text.charAt(0) == '+') { text = text.substring(1); } if (text.charAt(0) == '7') { StringBuilder strBuilder = new StringBuilder(text); strBuilder.setCharAt(0, '8'); text = strBuilder.toString(); } BigInteger dummy = new BigInteger(text); if (text.charAt(0) != '8' || text.length() != 11) { throw new Exception(); } } catch (Throwable t) { text = ""; //LOGE("convertPhoneNumberTo8Format: " + t.getMessage()); t.printStackTrace(); } return text; }
From source file:Main.java
public static final BigInteger castToBigInteger(Object paramObject) { if (paramObject == null) { return null; }// w ww. j a v a 2s . c om if ((paramObject instanceof BigInteger)) { return (BigInteger) paramObject; } if (((paramObject instanceof Float)) || ((paramObject instanceof Double))) { return BigInteger.valueOf(((Number) paramObject).longValue()); } String str = paramObject.toString(); if (str.length() == 0) { return null; } return new BigInteger(str); }
From source file:Main.java
public static PrivateKey getPrivateKey(String modulus, String privateExponent) throws NoSuchAlgorithmException, InvalidKeySpecException { BigInteger bigIntModulus = new BigInteger(modulus); BigInteger bigIntPrivateExponent = new BigInteger(privateExponent); RSAPublicKeySpec keySpec = new RSAPublicKeySpec(bigIntModulus, bigIntPrivateExponent); KeyFactory keyFactory = KeyFactory.getInstance(RSA); PrivateKey privateKey = keyFactory.generatePrivate(keySpec); return privateKey; }
From source file:Main.java
static Object bigIntegerElement(Element row, String name) { return new BigInteger(stringElement(row, name)); }
From source file:jp.co.ntts.vhut.util.MacConversionUtil.java
/** * ????????./* ww w . ja v a2 s .c o m*/ * @param macStart () * @param macEnd () * @return */ public static int getCount(String macStart, String macEnd) { BigInteger biMacStart = new BigInteger(addrToByte(macStart)); BigInteger biMacEnd = new BigInteger(addrToByte(macEnd)); return biMacEnd.subtract(biMacStart).intValue() + 1; }
From source file:Main.java
static PublicKey getRsaPublicKey(String n, String e) { BigInteger rsaN = null;/*from w ww. jav a 2s.c o m*/ BigInteger rsaE = null; try { rsaN = new BigInteger(n); rsaE = new BigInteger(e); } catch (Exception ex) { ex.printStackTrace(); } RSAPublicKeySpec pubRsaSpec = new RSAPublicKeySpec(rsaN, rsaE); try { KeyFactory keyfact = KeyFactory.getInstance("RSA", "SC"); PublicKey pk = keyfact.generatePublic(pubRsaSpec); Log.d("getRsaPublicKey", "pubRsaKey OK " + pk.getFormat()); return pk; } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:Main.java
/** * Parses the supplied xsd:integer string and returns its value. * //from w w w .j a v a2s .c om * @param s * A string representation of an xsd:integer value. * @return The integer value represented by the supplied string argument. * @throws NumberFormatException * If the supplied string is not a valid xsd:integer value. */ public static BigInteger parseInteger(String s) { s = trimPlusSign(s); return new BigInteger(s); }