BlowfishJ
Class BinConverter

java.lang.Object
  |
  +--BlowfishJ.BinConverter

public class BinConverter
extends java.lang.Object

some helper routines for data conversion, all data is treated in network byte order

Version:
January 12, 2003
Author:
Markus Hahn

Constructor Summary
BinConverter()
           
 
Method Summary
static int binHexToBytes(java.lang.String sBinHex, byte[] data, int nSrcOfs, int nDstOfs, int nLen)
          Converts a binhex string back into a byte array (invalid codes will be skipped).
static int byteArrayToInt(byte[] buf, int nOfs)
          Gets bytes from an array into an integer.
static long byteArrayToLong(byte[] buf, int nOfs)
          Gets bytes from an array into a long.
static java.lang.String byteArrayToUNCString(byte[] data, int nOfs, int nLen)
          Converts a byte array into an Unicode string.
static java.lang.String bytesToBinHex(byte[] data)
          Converts a byte array to a binhex string.
static java.lang.String bytesToBinHex(byte[] data, int nOfs, int nLen)
          Converts a byte array to a binhex string.
static long intArrayToLong(int[] buf, int nOfs)
          Converts values from an integer array to a long.
static void intToByteArray(int nValue, byte[] buf, int nOfs)
          Converts an integer to bytes, which are put into an array.
static int longHi32(long lVal)
          Gets the higher 32 bits of a long.
static int longLo32(long lVal)
          Gets the lower 32 bits of a long.
static void longToByteArray(long lValue, byte[] buf, int nOfs)
          Converts a long to bytes, which are put into an array.
static void longToIntArray(long lValue, int[] buf, int nOfs)
          Converts a long to integers which are put into an array.
static long makeLong(int nLo, int nHi)
          Makes a long from two integers (treated unsigned).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinConverter

public BinConverter()
Method Detail

byteArrayToInt

public static int byteArrayToInt(byte[] buf,
                                 int nOfs)
Gets bytes from an array into an integer.
Parameters:
buf - where to get the bytes
nOfs - index from where to read the data
Returns:
the 32bit integer

intToByteArray

public static void intToByteArray(int nValue,
                                  byte[] buf,
                                  int nOfs)
Converts an integer to bytes, which are put into an array.
Parameters:
nValue - the 32bit integer to convert
buf - the target buf
nOfs - where to place the bytes in the buf

byteArrayToLong

public static long byteArrayToLong(byte[] buf,
                                   int nOfs)
Gets bytes from an array into a long.
Parameters:
buf - where to get the bytes
nOfs - index from where to read the data
Returns:
the 64bit integer

longToByteArray

public static void longToByteArray(long lValue,
                                   byte[] buf,
                                   int nOfs)
Converts a long to bytes, which are put into an array.
Parameters:
lValue - the 64bit integer to convert
buf - the target buf
nOfs - where to place the bytes in the buf

intArrayToLong

public static long intArrayToLong(int[] buf,
                                  int nOfs)
Converts values from an integer array to a long.
Parameters:
buf - where to get the bytes
nOfs - index from where to read the data
Returns:
the 64bit integer

longToIntArray

public static void longToIntArray(long lValue,
                                  int[] buf,
                                  int nOfs)
Converts a long to integers which are put into an array.
Parameters:
lValue - the 64bit integer to convert
buf - the target buf
nOfs - where to place the bytes in the buf

makeLong

public static long makeLong(int nLo,
                            int nHi)
Makes a long from two integers (treated unsigned).
Parameters:
nLo - lower 32bits
nHi - higher 32bits
Returns:
the built long

longLo32

public static int longLo32(long lVal)
Gets the lower 32 bits of a long.
Parameters:
lVal - the long integer
Returns:
lower 32 bits

longHi32

public static int longHi32(long lVal)
Gets the higher 32 bits of a long.
Parameters:
lVal - the long integer
Returns:
higher 32 bits

bytesToBinHex

public static java.lang.String bytesToBinHex(byte[] data)
Converts a byte array to a binhex string.
Parameters:
data - the byte array
Returns:
the binhex string

bytesToBinHex

public static java.lang.String bytesToBinHex(byte[] data,
                                             int nOfs,
                                             int nLen)
Converts a byte array to a binhex string.
Parameters:
data - the byte array
nOfs - start index where to get the bytes
nLen - number of bytes to convert
Returns:
the binhex string

binHexToBytes

public static int binHexToBytes(java.lang.String sBinHex,
                                byte[] data,
                                int nSrcOfs,
                                int nDstOfs,
                                int nLen)
Converts a binhex string back into a byte array (invalid codes will be skipped).
Parameters:
sBinHex - binhex string
data - the target array
nSrcOfs - from which character in the string the conversion should begin, remember that (nSrcPos modulo 2) should equals 0 normally
nDstOfs - to store the bytes from which position in the array
nLen - number of bytes to extract
Returns:
number of extracted bytes

byteArrayToUNCString

public static java.lang.String byteArrayToUNCString(byte[] data,
                                                    int nOfs,
                                                    int nLen)
Converts a byte array into an Unicode string.
Parameters:
data - the byte array
nOfs - where to begin the conversion
nLen - number of bytes to handle
Returns:
the string