com.vgrs.xcode.common
Class Base32

java.lang.Object
  extended by com.vgrs.xcode.common.Base32

public final class Base32
extends java.lang.Object

Implements a Base 32 algorithm with encode and decode operations. The encode operation converts data on the range [0x00 - 0xff] to data on the range [a-z, 2-7]. The following table describes the conversion:

input base-32
bits hex hex char
00000 0x00 0x61 a
00001 0x01 0x62 b
00010 0x02 0x63 c
00011 0x03 0x64 d
00100 0x04 0x65 e
00101 0x05 0x66 f
00110 0x06 0x67 g
00111 0x07 0x68 h
01000 0x08 0x69 i
01001 0x09 0x6A j
01010 0x0A 0x6B k
01011 0x0B 0x6C l
01100 0x0C 0x6D m
01101 0x0D 0x6E n
01110 0x0E 0x6F o
01111 0x0F 0x70 p
10000 0x10 0x71 q
10001 0x11 0x72 r
10010 0x12 0x73 s
10011 0x13 0x74 t
10100 0x14 0x75 u
10101 0x15 0x76 v
10110 0x16 0x77 w
10111 0x17 0x78 x
11000 0x18 0x79 y
11001 0x19 0x7A z
11010 0x1A 0x32 2
11011 0x1B 0x33 3
11100 0x1C 0x34 4
11101 0x1D 0x35 5
11110 0x1E 0x36 6
11111 0x1F 0x37 7

data of size 1 bytes will be converted to 2 base-32 characters.
data of size 2 bytes will be converted to 4 base-32 characters.
data of size 3 bytes will be converted to 5 base-32 characters.
data of size 4 bytes will be converted to 7 base-32 characters.
data of size 5 bytes will be converted to 8 base-32 characters.


Field Summary
static byte ZERO
          Value of Ox0000
 
Constructor Summary
Base32()
           
 
Method Summary
static byte[] decode(char[] aInput)
          Decode a base 32 sequence into an array of bytes
static char[] encode(byte[] aInput)
          Encode a byte array into a base 32 sequence
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO

public static final byte ZERO
Value of Ox0000

See Also:
Constant Field Values
Constructor Detail

Base32

public Base32()
Method Detail

encode

public static char[] encode(byte[] aInput)
                     throws XcodeException
Encode a byte array into a base 32 sequence

Parameters:
aInput - the array of bytes on the range [0x00 - 0xff]
Returns:
Base 32 encoded string
Throws:
XcodeException - if the input string is null or with length == 0 or the input cannot be convert to a base-32 string.

decode

public static byte[] decode(char[] aInput)
                     throws XcodeException
Decode a base 32 sequence into an array of bytes

Parameters:
aInput - Base 32 encoded string
Returns:
a byte array
Throws:
XcodeException - if the input string is null or with length == 0 or the input cannot be convert to a native string.


Copyright © 2000-2010 VeriSign Inc. All Rights Reserved