private static double generateAngle(String identifier, int correction) { String hash = SHA1.hex(identifier); String first16bits = hash.substring(0, 4); String littleEndian = first16bits.substring(2) + first16bits.substring(0, 2); double angle = (double) Integer.parseInt(littleEndian, 16) / 65535 * 2 * Math.PI; switch (correction) { case CORRECTION_REDGREEN: angle /= 2; break; case CORRECTION_BLUE: angle = (angle / 2) + (Math.PI / 2); break; } return angle; }
/** * Returns a SHA-1 digest of the given parameters as specified in <a * href="http://xmpp.org/extensions/xep-0065.html#impl-socks5">XEP-0065</a>. * * @param sessionID for the SOCKS5 Bytestream * @param initiatorJID JID of the initiator of a SOCKS5 Bytestream * @param targetJID JID of the target of a SOCKS5 Bytestream * @return SHA-1 digest of the given parameters */ public static String createDigest(String sessionID, String initiatorJID, String targetJID) { StringBuilder b = new StringBuilder(); b.append(sessionID).append(initiatorJID).append(targetJID); return SHA1.hex(b.toString()); }