Class Base32
- java.lang.Object
-
- com.inductiveautomation.ignition.common.licensing.Base32
-
public class Base32 extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Base32()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
bitSetToByteArray(java.util.BitSet bs, int numBits)
This function will take a BitSet, whose byte order is LSB->MSB, and create a byte[] whose bytes are in the same order.static java.util.BitSet
decode(java.lang.String s)
Takes string s, which should be a number encoded in Base32.static java.lang.String
encode(byte[] bytes)
This function will encode the byte array 'bytes' into a Base-32 formatted string using charactors 1-9, A-X, skipping zero and 'O'.static java.lang.String
encode(java.util.BitSet bits, int nbits)
This function takes a BitSet, whose LSB is in position 0 and whose MSB is in position length-1, and turns it into a Base32 string whose endianness is opposite, MSB-LSB, similar to how one would write a hex string.static char
getChar(int i)
static boolean
ithBitSet(byte b, int i)
-
-
-
Method Detail
-
encode
public static java.lang.String encode(byte[] bytes)
This function will encode the byte array 'bytes' into a Base-32 formatted string using charactors 1-9, A-X, skipping zero and 'O'. Note that if the number of bits (length*8) is not divisible by 5, then zeroes will be padded onto the MSB side of the intermediate BitSet. This means that when the resulting Base32 String is decoded, you may get an extra byte of all zeroes.- Parameters:
bytes
- an array of bytes. Note that the bytes in the lower indices will be treated as lower significance. So, {0xab, 0xcd, 0xef} will be the hex number 0xefcdab- Returns:
- a String encoding bytes in Base-32
-
encode
public static java.lang.String encode(java.util.BitSet bits, int nbits)
This function takes a BitSet, whose LSB is in position 0 and whose MSB is in position length-1, and turns it into a Base32 string whose endianness is opposite, MSB-LSB, similar to how one would write a hex string.
-
decode
public static java.util.BitSet decode(java.lang.String s)
Takes string s, which should be a number encoded in Base32. Note that the string s has its LSB in the rightmost character, and the MSB in the leftmost char. For instance, s = ART3B7 MSB <-->LSB Note that this is similar to how one would write a hex number, i.e. 0xABCD- Returns:
- This function will return a BitSet which contains the binary number that s represents. The bitset will have its LSB at position 0, and its MSB at position length-1.
-
bitSetToByteArray
public static byte[] bitSetToByteArray(java.util.BitSet bs, int numBits)
This function will take a BitSet, whose byte order is LSB->MSB, and create a byte[] whose bytes are in the same order. Note that the byte array may have more bits that the BitSet, as the length of the byte array in bits will be an even multiple of 8, whereas the length it bits of the BitSet will most likely be a multiple of 5. Hence, the last byte in the byte array will probably start with three zeroes.- Parameters:
bs
- the LSB->MSB bit set to convert.numBits
- The number of bits in the bit set to process.
-
ithBitSet
public static boolean ithBitSet(byte b, int i)
-
getChar
public static char getChar(int i)
-
-