class MultiChainAddressGenerator {

    public static String getPublicAddress(String[] version, String addressChecksum, byte[] pubKey) {
        //Step 3
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("SHA-256");
            digest.reset();
            byte[] hash = digest.digest(pubKey);

            //Step 4
            RIPEMD160Digest ripemd = new RIPEMD160Digest();
            ripemd.update(hash, 0, hash.length);
            byte[] out = new byte[20];
            ripemd.doFinal(out, 0);
            String hashStr = Util.byteArrayToHexString(out);

            //Step 5
            String step5 = "";
            if (BuildConfig.DEBUG && version.length != 4) throw new AssertionError("Version length != 4");
            for (int i = 0; i < 4; i++) { //Assumes version.length == 4
                step5 += version[i] + hashStr.substring((i*10),(i*10)+10);
            }
            digest.reset();

            //Step 6
            byte[] step6 = digest.digest(Util.hexStringToByteArray(step5));
            digest.reset();

            //Step 7
            byte[] step7 = digest.digest(step6);
            digest.reset();

            //Step 8
            byte[] checksum = new byte[]{ step7[0],step7[1],step7[2],step7[3] };

            //Step 9
            byte[] byteAddressChecksum = Util.hexStringToByteArray(addressChecksum);
            byte[] xor = new byte[4];
            for (int i = 0; i < 4; i++) {
                int xorvalue = (int)checksum[i] ^ (int)byteAddressChecksum[i];
                xor[i] = (byte)(0xff & xorvalue);
            }

            //Step 10
            String addressbytes = step5 + Util.byteArrayToHexString(xor);

            //Step 11
            String address = Base58.encode(Util.hexStringToByteArray(addressbytes));
            return address;
        } catch (NoSuchAlgorithmException e1) {
            e1.printStackTrace();
            return null;
        }
    }

}