Bech32 { public static byte[] decodeCashAddress(String bitcoinCashAddress) { if (!isValidCashAddress(bitcoinCashAddress)) { throw new RuntimeException("Address wasn't valid: " + bitcoinCashAddress); } String[] addressParts = bitcoinCashAddress.split(SEPARATOR); int datapos = 0; if (addressParts.length == 2) { String prefix = addressParts[0]; datapos++; } byte[] addressData = Bech32.decodeFromCharset(addressParts[datapos]); addressData = Arrays.copyOfRange(addressData, 0, addressData.length - 8); addressData = convertBits(addressData, 5, 8, true); byte versionByte = addressData[0]; return Arrays.copyOfRange(addressData, 1, addressData.length); }  static byte[] calculateChecksumBytesPolymod(byte[] checksumInput); static byte[] decodeFromCharset(String base32String); static String encodeToCharset(byte[] data); static String encodeHashToBech32Address(String humanPart, int version, byte[] pubKeyHash); static byte[] decodeCashAddress(String bitcoinCashAddress); static boolean isValidCashAddress(String bitcoinCashAddress); static byte[] concatenateByteArrays(byte[] ... arrays ); static byte[] encodePrefixToUInt5(String prefixString); static long bytes2Long(byte[] bytes); static final String SEPARATOR; static final String MAIN_NET_PREFIX; static final String CHARSET; }
@Test public void test() { assertEquals("11DstTXVTvo8DfczCQws6CHV718u74VV2", LegacyAddress.fromPubKeyHash(MainNetParams.get(), Bech32.decodeCashAddress("qqqq4077ywes2cmda80crheea4m7zznszvk5lqedw9")).toString()); assertEquals("1P3GQYtcWgZHrrJhUa4ctoQ3QoCU2F65nz", LegacyAddress.fromPubKeyHash(MainNetParams.get(), Bech32.decodeCashAddress("bitcoincash:qrcuqadqrzp2uztjl9wn5sthepkg22majyxw4gmv6p")).toString()); assertEquals("17WXKozdmX7zfjPRLZtJz5Avth4E3kq3xn", LegacyAddress.fromPubKeyHash(MainNetParams.get(), Bech32.decodeCashAddress("qprkvgvvlvn856mkhuuh0kxtu7ngnu2sr5xhsvwye4")).toString()); }