For the latest news and information visit
The GNU Crypto project

gnu.crypto.util
Class Util

java.lang.Object
  |
  +--gnu.crypto.util.Util

public class Util
extends java.lang.Object

A collection of utility methods used throughout this project.

Version:
$Revision: 1.4 $

Method Summary
static boolean areEqual(byte[] a, byte[] b)
          Returns true if the two designated byte arrays are (a) non-null, (b) of the same length, and (c) contain the same values.
static int fromDigit(char c)
          Returns a number from 0 to 15 corresponding to the designated hexadecimal digit.
static byte[] toBytesFromString(java.lang.String s)
          Returns a byte array from a string of hexadecimal digits.
static byte[] toBytesFromUnicode(java.lang.String s)
           
static java.lang.String toString(byte[] ba)
          Returns a string of hexadecimal digits from a byte array.
static java.lang.String toString(byte[] ba, int offset, int length)
          Returns a string of hexadecimal digits from a byte array, starting at offset and consisting of length bytes.
static java.lang.String toString(int n)
          Returns a string of 8 hexadecimal digits (most significant digit first) corresponding to the unsigned integer n.
static java.lang.String toString(int[] ia)
          Returns a string of hexadecimal digits from an integer array.
static java.lang.String toString(long n)
          Returns a string of 16 hexadecimal digits (most significant digit first) corresponding to the unsigned long n.
static java.lang.String toUnicodeString(byte[] ba)
          Similar to the toString() method except that the Unicode escape character is inserted before every pair of bytes.
static java.lang.String toUnicodeString(byte[] ba, int offset, int length)
          Similar to the toString() method except that the Unicode escape character is inserted before every pair of bytes.
static java.lang.String toUnicodeString(int[] ia)
          Similar to the toString() method except that the Unicode escape character is inserted before every pair of bytes.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

areEqual

public static boolean areEqual(byte[] a,
                               byte[] b)

Returns true if the two designated byte arrays are (a) non-null, (b) of the same length, and (c) contain the same values.

Parameters:
a - the first byte array.
b - the second byte array.
Returns:
true if the two designated arrays contain the same values. Returns false otherwise.

toString

public static java.lang.String toString(byte[] ba)

Returns a string of hexadecimal digits from a byte array. Each byte is converted to 2 hex symbols; zero(es) included.

This method calls the method with same name and three arguments as:

    toString(ba, 0, ba.length);
 
Parameters:
ba - the byte array to convert.
Returns:
a string of hexadecimal characters (two for each byte) representing the designated input byte array.

toString

public static final java.lang.String toString(byte[] ba,
                                              int offset,
                                              int length)

Returns a string of hexadecimal digits from a byte array, starting at offset and consisting of length bytes. Each byte is converted to 2 hex symbols; zero(es) included.

Parameters:
ba - the byte array to convert.
offset - the index from which to start considering the bytes to convert.
length - the count of bytes, starting from the designated offset to convert.
Returns:
a string of hexadecimal characters (two for each byte) representing the designated input byte sub-array.

toBytesFromString

public static byte[] toBytesFromString(java.lang.String s)

Returns a byte array from a string of hexadecimal digits.

Parameters:
s - a string of hexadecimal ASCII characters
Returns:
the decoded byte array from the input hexadecimal string.

fromDigit

public static int fromDigit(char c)

Returns a number from 0 to 15 corresponding to the designated hexadecimal digit.

Parameters:
c - a hexadecimal ASCII symbol.

toString

public static java.lang.String toString(int n)

Returns a string of 8 hexadecimal digits (most significant digit first) corresponding to the unsigned integer n.

Parameters:
n - the unsigned integer to convert.
Returns:
a hexadecimal string 8-character long.

toString

public static java.lang.String toString(int[] ia)

Returns a string of hexadecimal digits from an integer array. Each int is converted to 4 hex symbols.


toString

public static java.lang.String toString(long n)

Returns a string of 16 hexadecimal digits (most significant digit first) corresponding to the unsigned long n.

Parameters:
n - the unsigned long to convert.
Returns:
a hexadecimal string 16-character long.

toUnicodeString

public static java.lang.String toUnicodeString(byte[] ba)

Similar to the toString() method except that the Unicode escape character is inserted before every pair of bytes. Useful to externalise byte arrays that will be constructed later from such strings; eg. s-box values.

Throws:
ArrayIndexOutOfBoundsException - if the length is odd.

toUnicodeString

public static final java.lang.String toUnicodeString(byte[] ba,
                                                     int offset,
                                                     int length)

Similar to the toString() method except that the Unicode escape character is inserted before every pair of bytes. Useful to externalise byte arrays that will be constructed later from such strings; eg. s-box values.

Throws:
ArrayIndexOutOfBoundsException - if the length is odd.

toUnicodeString

public static java.lang.String toUnicodeString(int[] ia)

Similar to the toString() method except that the Unicode escape character is inserted before every pair of bytes. Useful to externalise integer arrays that will be constructed later from such strings; eg. s-box values.

Throws:
ArrayIndexOutOfBoundsException - if the length is not a multiple of 4.

toBytesFromUnicode

public static byte[] toBytesFromUnicode(java.lang.String s)

For the latest news and information visit
The GNU Crypto project

Copyright ©2001-2002 Free Software Foundation, Inc.. All Rights Reserved.