@Test public void testTranslate_leading_nulls() throws Exception { Base58ByteTranslator b = new Base58ByteTranslator(); String b58 = Base58.encode(BYTES_WITH_NULLS); assertEquals(b58, b.translate(b.translate(b58))); }
public static String encode(byte[] input) { if (input.length == 0) { return ""; } int zeros = 0; while (zeros < input.length && input[zeros] == 0) { ++zeros; } input = Arrays.copyOf(input, input.length); char[] encoded = new char[input.length * 2]; int outputStart = encoded.length; for (int inputStart = zeros; inputStart < input.length;) { encoded[--outputStart] = ALPHABET[divmod(input, inputStart, 256, 58)]; if (input[inputStart] == 0) { ++inputStart; } } while (outputStart < encoded.length && encoded[outputStart] == ENCODED_ZERO) { ++outputStart; } while (--zeros >= 0) { encoded[--outputStart] = ENCODED_ZERO; } return new String(encoded, outputStart, encoded.length - outputStart); }
Base58 { public static String encode(byte[] input) { if (input.length == 0) { return ""; } int zeros = 0; while (zeros < input.length && input[zeros] == 0) { ++zeros; } input = Arrays.copyOf(input, input.length); char[] encoded = new char[input.length * 2]; int outputStart = encoded.length; for (int inputStart = zeros; inputStart < input.length;) { encoded[--outputStart] = ALPHABET[divmod(input, inputStart, 256, 58)]; if (input[inputStart] == 0) { ++inputStart; } } while (outputStart < encoded.length && encoded[outputStart] == ENCODED_ZERO) { ++outputStart; } while (--zeros >= 0) { encoded[--outputStart] = ENCODED_ZERO; } return new String(encoded, outputStart, encoded.length - outputStart); } }
Base58 { public static String encode(byte[] input) { if (input.length == 0) { return ""; } int zeros = 0; while (zeros < input.length && input[zeros] == 0) { ++zeros; } input = Arrays.copyOf(input, input.length); char[] encoded = new char[input.length * 2]; int outputStart = encoded.length; for (int inputStart = zeros; inputStart < input.length;) { encoded[--outputStart] = ALPHABET[divmod(input, inputStart, 256, 58)]; if (input[inputStart] == 0) { ++inputStart; } } while (outputStart < encoded.length && encoded[outputStart] == ENCODED_ZERO) { ++outputStart; } while (--zeros >= 0) { encoded[--outputStart] = ENCODED_ZERO; } return new String(encoded, outputStart, encoded.length - outputStart); }  }
Base58 { public static String encode(byte[] input) { if (input.length == 0) { return ""; } int zeros = 0; while (zeros < input.length && input[zeros] == 0) { ++zeros; } input = Arrays.copyOf(input, input.length); char[] encoded = new char[input.length * 2]; int outputStart = encoded.length; for (int inputStart = zeros; inputStart < input.length;) { encoded[--outputStart] = ALPHABET[divmod(input, inputStart, 256, 58)]; if (input[inputStart] == 0) { ++inputStart; } } while (outputStart < encoded.length && encoded[outputStart] == ENCODED_ZERO) { ++outputStart; } while (--zeros >= 0) { encoded[--outputStart] = ENCODED_ZERO; } return new String(encoded, outputStart, encoded.length - outputStart); }  static String encode(byte[] input); static byte[] decode(String input); }
Base58 { public static String encode(byte[] input) { if (input.length == 0) { return ""; } int zeros = 0; while (zeros < input.length && input[zeros] == 0) { ++zeros; } input = Arrays.copyOf(input, input.length); char[] encoded = new char[input.length * 2]; int outputStart = encoded.length; for (int inputStart = zeros; inputStart < input.length;) { encoded[--outputStart] = ALPHABET[divmod(input, inputStart, 256, 58)]; if (input[inputStart] == 0) { ++inputStart; } } while (outputStart < encoded.length && encoded[outputStart] == ENCODED_ZERO) { ++outputStart; } while (--zeros >= 0) { encoded[--outputStart] = ENCODED_ZERO; } return new String(encoded, outputStart, encoded.length - outputStart); }  static String encode(byte[] input); static byte[] decode(String input);  }