plebble
us.gov.crypto.base58 Class Reference
Collaboration diagram for us.gov.crypto.base58:

Classes

class  AddressFormatException
 

Static Public Member Functions

static String encode (byte[] input_)
 
static byte[] copyOfRange (byte[] src, int start, int end)
 
static byte[] decode (String input)
 
static String encode (byte[] input)
 
static String decode_string (String input)
 
static byte[] decode (String input) throws AddressFormatException
 

Static Public Attributes

static readonly char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".ToCharArray()
 
static final char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".toCharArray()
 

Static Package Functions

 [static initializer]
 

Static Private Member Functions

static base58 ()
 
static byte divmod (byte[] number, int firstDigit, int based, int divisor)
 
static byte divmod (byte[] number, int firstDigit, int base, int divisor)
 

Static Private Attributes

static readonly char ENCODED_ZERO = ALPHABET[0]
 
static readonly int[] INDEXES = new int[128]
 
static final char ENCODED_ZERO = ALPHABET[0]
 
static final int[] INDEXES = new int[128]
 

Detailed Description

Base58 is a way to encode Bitcoin addresses (or arbitrary data) as alphanumeric strings.

Note that this is not the same base58 as used by Flickr, which you may find referenced around the Internet.

You may want to consider working with PrefixedChecksummedBytes instead, which adds support for testing the prefix and suffix bytes commonly found in addresses.

Satoshi explains: why base-58 instead of standard base-64 encoding?

  • Don't want 0OIl characters that look the same in some fonts and could be used to create visually identical looking account numbers.
  • A string with non-alphanumeric characters is not as easily accepted as an account number.
  • E-mail usually won't line-break if there's no punctuation to break at.
  • Doubleclicking selects the whole number as one word if it's all alphanumeric.

However, note that the encoding/decoding runs in O(n²) time, so it is not useful for large data.

The basic idea of the encoding is to treat the data bytes as a large number represented using base-256 digits, convert the number to be represented using base-58 digits, preserve the exact number of leading zeros (which are otherwise lost during the mathematical operations on the numbers), and finally represent the resulting base-58 digits as alphanumeric ASCII characters.

Constructor & Destructor Documentation

◆ base58()

static us.gov.crypto.base58.base58 ( )
inlinestaticprivate

Member Function Documentation

◆ [static initializer]()

us.gov.crypto.base58.[static initializer]
inlinestaticpackage

◆ copyOfRange()

static byte [] us.gov.crypto.base58.copyOfRange ( byte[]  src,
int  start,
int  end 
)
inlinestatic

Referenced by us.gov.crypto.base58.decode().

Here is the caller graph for this function:

◆ decode() [1/2]

static byte [] us.gov.crypto.base58.decode ( String  input)
inlinestatic

◆ decode() [2/2]

static byte [] us.gov.crypto.base58.decode ( String  input) throws AddressFormatException
inlinestatic

Decodes the given base58 string into the original data bytes.

Parameters
inputthe base58-encoded string to decode
Returns
the decoded data bytes
Exceptions
AddressFormatExceptionif the given string is not a valid base58 string

References us.gov.crypto.base58.divmod(), and us.gov.crypto.base58.INDEXES.

Here is the call graph for this function:

◆ decode_string()

static String us.gov.crypto.base58.decode_string ( String  input)
inlinestatic

References us.gov.crypto.base58.decode().

Here is the call graph for this function:

◆ divmod() [1/2]

static byte us.gov.crypto.base58.divmod ( byte[]  number,
int  firstDigit,
int  base,
int  divisor 
)
inlinestaticprivate

Divides a number, represented as an array of bytes each containing a single digit in the specified base, by the given divisor. The given number is modified in-place to contain the quotient, and the return value is the remainder.

Parameters
numberthe number to divide
firstDigitthe index within the array of the first non-zero digit (this is used for optimization by skipping the leading zeros)
basethe base in which the number's digits are represented (up to 256)
divisorthe number to divide by (up to 256)
Returns
the remainder of the division operation

◆ divmod() [2/2]

static byte us.gov.crypto.base58.divmod ( byte[]  number,
int  firstDigit,
int  based,
int  divisor 
)
inlinestaticprivate

Divides a number, represented as an array of bytes each containing a single digit in the specified base, by the given divisor. The given number is modified in-place to contain the quotient, and the return value is the remainder.

Parameters
numberthe number to divide
firstDigitthe index within the array of the first non-zero digit (this is used for optimization by skipping the leading zeros)
basethe base in which the number's digits are represented (up to 256)
divisorthe number to divide by (up to 256)
Returns
the remainder of the division operation

Referenced by us.gov.crypto.base58.decode(), and us.gov.crypto.base58.encode().

Here is the caller graph for this function:

◆ encode() [1/2]

static String us.gov.crypto.base58.encode ( byte[]  input)
inlinestatic

Encodes the given bytes as a base58 string (no checksum is appended).

Parameters
inputthe bytes to encode
Returns
the base58-encoded string

References us.gov.crypto.base58.ALPHABET, us.gov.crypto.base58.divmod(), and us.gov.crypto.base58.ENCODED_ZERO.

Here is the call graph for this function:

◆ encode() [2/2]

static String us.gov.crypto.base58.encode ( byte[]  input_)
inlinestatic

Member Data Documentation

◆ ALPHABET [1/2]

readonly char [] us.gov.crypto.base58.ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".ToCharArray()
static

◆ ALPHABET [2/2]

final char [] us.gov.crypto.base58.ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".toCharArray()
static

◆ ENCODED_ZERO [1/2]

readonly char us.gov.crypto.base58.ENCODED_ZERO = ALPHABET[0]
staticprivate

◆ ENCODED_ZERO [2/2]

final char us.gov.crypto.base58.ENCODED_ZERO = ALPHABET[0]
staticprivate

◆ INDEXES [1/2]

readonly int [] us.gov.crypto.base58.INDEXES = new int[128]
staticprivate

◆ INDEXES [2/2]

final int [] us.gov.crypto.base58.INDEXES = new int[128]
staticprivate

The documentation for this class was generated from the following files: