public static byte[] decode(String input) throws ParseException {
  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 ParseException("Illegal character " + c + " at position "+ i,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);
}

public static byte [ ] decode ( String input ) throws ParseException { 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 ParseException ( "Illegal character " + c + " at position " + i , 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 ) ; }
decodes the given base58 string into the original data bytes .
