@Test(expected = AddressFormatException.class) public void testDecode_invalidBase58() { Base58.decode("This isn't valid base58"); }
public static byte[] decode(String input) throws AddressFormatException { if (input.length() == 0) { return new byte[0]; } byte[] input58 = new byte[input.length()]; for (int i = 0; i < input.length(); ++i) { char c = input.charAt(i); int digit = c < 128 ? INDEXES[c] : -1; if (digit < 0) { throw new AddressFormatException.InvalidCharacter(c, i); } input58[i] = (byte) digit; } int zeros = 0; while (zeros < input58.length && input58[zeros] == 0) { ++zeros; } byte[] decoded = new byte[input.length()]; int outputStart = decoded.length; for (int inputStart = zeros; inputStart < input58.length; ) { decoded[--outputStart] = divmod(input58, inputStart, 58, 256); if (input58[inputStart] == 0) { ++inputStart; } } while (outputStart < decoded.length && decoded[outputStart] == 0) { ++outputStart; } return Arrays.copyOfRange(decoded, outputStart - zeros, decoded.length); }
Base58 { public static byte[] decode(String input) throws AddressFormatException { if (input.length() == 0) { return new byte[0]; } byte[] input58 = new byte[input.length()]; for (int i = 0; i < input.length(); ++i) { char c = input.charAt(i); int digit = c < 128 ? INDEXES[c] : -1; if (digit < 0) { throw new AddressFormatException.InvalidCharacter(c, i); } input58[i] = (byte) digit; } int zeros = 0; while (zeros < input58.length && input58[zeros] == 0) { ++zeros; } byte[] decoded = new byte[input.length()]; int outputStart = decoded.length; for (int inputStart = zeros; inputStart < input58.length; ) { decoded[--outputStart] = divmod(input58, inputStart, 58, 256); if (input58[inputStart] == 0) { ++inputStart; } } while (outputStart < decoded.length && decoded[outputStart] == 0) { ++outputStart; } return Arrays.copyOfRange(decoded, outputStart - zeros, decoded.length); } }
Base58 { public static byte[] decode(String input) throws AddressFormatException { if (input.length() == 0) { return new byte[0]; } byte[] input58 = new byte[input.length()]; for (int i = 0; i < input.length(); ++i) { char c = input.charAt(i); int digit = c < 128 ? INDEXES[c] : -1; if (digit < 0) { throw new AddressFormatException.InvalidCharacter(c, i); } input58[i] = (byte) digit; } int zeros = 0; while (zeros < input58.length && input58[zeros] == 0) { ++zeros; } byte[] decoded = new byte[input.length()]; int outputStart = decoded.length; for (int inputStart = zeros; inputStart < input58.length; ) { decoded[--outputStart] = divmod(input58, inputStart, 58, 256); if (input58[inputStart] == 0) { ++inputStart; } } while (outputStart < decoded.length && decoded[outputStart] == 0) { ++outputStart; } return Arrays.copyOfRange(decoded, outputStart - zeros, decoded.length); }  }
Base58 { public static byte[] decode(String input) throws AddressFormatException { if (input.length() == 0) { return new byte[0]; } byte[] input58 = new byte[input.length()]; for (int i = 0; i < input.length(); ++i) { char c = input.charAt(i); int digit = c < 128 ? INDEXES[c] : -1; if (digit < 0) { throw new AddressFormatException.InvalidCharacter(c, i); } input58[i] = (byte) digit; } int zeros = 0; while (zeros < input58.length && input58[zeros] == 0) { ++zeros; } byte[] decoded = new byte[input.length()]; int outputStart = decoded.length; for (int inputStart = zeros; inputStart < input58.length; ) { decoded[--outputStart] = divmod(input58, inputStart, 58, 256); if (input58[inputStart] == 0) { ++inputStart; } } while (outputStart < decoded.length && decoded[outputStart] == 0) { ++outputStart; } return Arrays.copyOfRange(decoded, outputStart - zeros, decoded.length); }  static String encode(byte[] input); static String encodeChecked(int version, byte[] payload); static byte[] decode(String input); static BigInteger decodeToBigInteger(String input); static byte[] decodeChecked(String input); }
Base58 { public static byte[] decode(String input) throws AddressFormatException { if (input.length() == 0) { return new byte[0]; } byte[] input58 = new byte[input.length()]; for (int i = 0; i < input.length(); ++i) { char c = input.charAt(i); int digit = c < 128 ? INDEXES[c] : -1; if (digit < 0) { throw new AddressFormatException.InvalidCharacter(c, i); } input58[i] = (byte) digit; } int zeros = 0; while (zeros < input58.length && input58[zeros] == 0) { ++zeros; } byte[] decoded = new byte[input.length()]; int outputStart = decoded.length; for (int inputStart = zeros; inputStart < input58.length; ) { decoded[--outputStart] = divmod(input58, inputStart, 58, 256); if (input58[inputStart] == 0) { ++inputStart; } } while (outputStart < decoded.length && decoded[outputStart] == 0) { ++outputStart; } return Arrays.copyOfRange(decoded, outputStart - zeros, decoded.length); }  static String encode(byte[] input); static String encodeChecked(int version, byte[] payload); static byte[] decode(String input); static BigInteger decodeToBigInteger(String input); static byte[] decodeChecked(String input); static final char[] ALPHABET; }