Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@
</profiles>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/chrylis/codec/base58/Base58Codec.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;

import org.apache.commons.lang3.ArrayUtils;

/**
* The operations contained in this class are confined to their methods and are entirely thread-safe. In fact, all of the methods
* are implemented statically, and the instance-bound {@link #encode(byte[])} and {@link #decode(String)} methods are non-static
Expand Down Expand Up @@ -40,7 +39,13 @@ public class Base58Codec {
* {@code byte[]}.
*/
public static final char ALPHABET[] = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ".toCharArray();

private static final int[] ALPHABET_INDEXES = new int[BLOCK_LENGTH_DIGITS];
static {
Arrays.fill(ALPHABET_INDEXES, -1);
for (int i = 0; i < ALPHABET.length; i++) {
ALPHABET_INDEXES[ALPHABET[i]] = i;
}
}
/**
* Encode a stream of MSB-ordered bytes into Base58. Automatically pads negative numbers with a leading zero byte.
*
Expand Down Expand Up @@ -120,7 +125,7 @@ public static byte[] doDecode(final String source) {

Iterator<Character> it = stringIterator(source);
while (it.hasNext()) {
value = value.add(BigInteger.valueOf(ArrayUtils.indexOf(ALPHABET, it.next())));
value = value.add(BigInteger.valueOf(ALPHABET_INDEXES[it.next()]));
if (it.hasNext())
value = value.multiply(BASE);
}
Expand Down