List of usage examples for java.math BigInteger BigInteger
private BigInteger(byte[] magnitude, int signum)
From source file:biz.karms.sinkit.ejb.util.CIDRUtils.java
public static ImmutablePair<String, String> getStartEndAddresses(final String cidr) throws UnknownHostException { //TODO: This is silly. Refactor CIDRUtils so as to accept actual IPs as well as subnets. //TODO: Validate the thing before processing. Guava? final String fixedCIDR; if (!cidr.contains("/")) { //IPv6? Hmmm... if (cidr.contains(":")) { fixedCIDR = cidr + "/128"; } else {// ww w.ja v a 2 s .c o m fixedCIDR = cidr + "/32"; } } else { fixedCIDR = cidr; } final int index = fixedCIDR.indexOf("/"); final InetAddress inetAddress = InetAddress.getByName(fixedCIDR.substring(0, index)); final int prefixLength = Integer.parseInt(fixedCIDR.substring(index + 1)); final ByteBuffer maskBuffer; if (inetAddress.getAddress().length == 4) { maskBuffer = ByteBuffer.allocate(4).putInt(-1); } else { maskBuffer = ByteBuffer.allocate(16).putLong(-1L).putLong(-1L); } final BigInteger mask = (new BigInteger(1, maskBuffer.array())).not().shiftRight(prefixLength); final ByteBuffer buffer = ByteBuffer.wrap(inetAddress.getAddress()); final BigInteger ipVal = new BigInteger(1, buffer.array()); final BigInteger startIp = ipVal.and(mask); final BigInteger endIp = startIp.add(mask.not()); return new ImmutablePair<>(String.format("%040d", startIp), String.format("%040d", endIp)); }
From source file:springmvc.service.PersonServiceImpl.java
public String generate() { SecureRandom random = new SecureRandom(); String pw = new BigInteger(130, random).toString(32); return pw.substring(0, 10); }
From source file:de.upb.wdqa.wdvd.revisiontags.SHA1Converter.java
private static String getBase(int base, byte[] bytes) { String result;/* w ww . j a v a 2s. c o m*/ if (bytes != null) { if (bytes.length != 0) { BigInteger bi = new BigInteger(1, bytes); String tmp = bi.toString(base); int numberOfDigits = (int) Math.ceil(160.0 / (Math.log(base) / Math.log(2.0))); result = StringUtils.leftPad(tmp, numberOfDigits, '0'); } else { result = ""; } } else { result = null; } return result; }
From source file:camera.Camera.java
public Camera() throws MqttException, SocketException { System.out.println("Log4J: " + HoraFile.getCanonicalPath(LOG4J)); System.out.println("Ini: " + HoraFile.getCanonicalPath(INI)); DOMConfigurator.configureAndWatch(LOG4J, 10 * 1000); MQTTLINK = HoraIni.LeseIniString(INI, "MQTT", "LINK_PORT", MQTTLINK, true); MQTTLINK = "tcp://" + MQTTLINK; //// w w w .j a v a 2 s.c o m this.mac = TestMac.getMacAddress("wlan"); MemoryPersistence persistence = new MemoryPersistence(); SecureRandom random = new SecureRandom(); String id = new BigInteger(60, random).toString(32); System.out.println("camid=" + id); client = new MqttClient(MQTTLINK, id, persistence); client.setTimeToWait(5000); }
From source file:com.github.badoualy.badoualyve.GameEngine.java
public User generateNewUser(String name) { User user = new User(); user.name = getFreeName(name);/*from www. j av a2s .com*/ user.token = new BigInteger(130, random).toString(32).replace(" ", ""); user.attack = 100 + random.nextInt(50); user.defense = 100 + random.nextInt(50); user.speed = 100 + random.nextInt(30); user.hp = 1000 + random.nextInt(200); user.lastUpdateTime = System.currentTimeMillis(); userList.add(user); return user; }
From source file:edu.mit.media.funf.HashUtil.java
public static String oneWayHashString(String msg) { MessageDigest md = getMessageDigest(); synchronized (md) { if (msg == null || "".equals(msg)) { return ""; } else if (md == null) { return "NO SHA"; } else {/* w w w.j a v a 2 s .c om*/ byte[] msgDigest = md.digest(msg.getBytes()); BigInteger number = new BigInteger(1, msgDigest); return number.toString(16); } } }
From source file:de.u808.common.MD5Util.java
/** * Creates MD5 Hex String for the input. * //from w w w .j a va 2 s .c o m * @param s The string to create the hash for. * @return The MD5 Hex String for the input string. */ public String getMD5Hex(String s) { md.update(s.getBytes(), 0, s.length()); String md5Hex = new BigInteger(1, md.digest()).toString(16); md.reset(); return md5Hex; }
From source file:net.sf.keystore_explorer.utilities.io.HexUtil.java
/** * Get hex string for the supplied byte array: "0x<hex string>" where hex * string is outputted in groups of exactly four characters sub-divided by * spaces.// www .j a v a 2s . c o m * * @param bytes * Byte array * @return Hex string */ public static String getHexString(byte[] bytes) { return getHexString(new BigInteger(1, bytes)); }
From source file:com.jim.im.offline.repo.MessageConverter.java
private static Object getValue(Field field, Object sourceValue) { if (sourceValue == null) return null; if (field.getType() == MsgType.class) { return MsgType.valueOf(sourceValue.toString()); } else if (field.getType() == TopicOwnerType.class) { return TopicOwnerType.valueOf(sourceValue.toString()); } else if (field.getType() == BigInteger.class) { return new BigInteger(sourceValue.toString(), 16); }// w ww. ja va2 s. co m return sourceValue; }
From source file:com.google.wolff.androidhunt.Hunt.java
/** Returns the singleton hunt object, and initializes it if it's not ready. */ public static Hunt getHunt(Resources res, Context context) { if (theHunt == null) { hrm = new HuntResourceManager(); hrm.unzipFile(res);//from w ww . java2 s . co m theHunt = new Hunt(hrm.huntJSON, res, context); String android_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); if (android_id == null) { // Fall back on devices where ANDROID_ID is not reliable. theHunt.shuffle(Integer.parseInt(Settings.Secure.ANDROID_ID, 0)); } else { BigInteger bi = new BigInteger(android_id, 16); System.out.println(bi); theHunt.shuffle(bi.shortValue()); } } return theHunt; }