XORArrayOfBytes
public static byte[] XORArrayOfBytes(byte[] a,
byte[] b)
addArrayOfBytes
public static byte[] addArrayOfBytes(byte[] a,
byte[] b)
crc32
public static long crc32(byte[] s,
int len)
Compute the crc Cyclic Redundancy Check, with the polynomial 0xedb88320,
The polynomial is X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
We take it "backwards" and put the highest-order term in the lowest-order bit.
The X^32 term is "implied"; the LSB is the X^31 term, etc.
The X^0 term (usually shown as "+1") results in the MSB being 1.
so the poly is 0x04c11db7 (used for Ethernet)
The buf will be the Padding, Packet type, and Data fields.
The crc is computed before any encryption.
R =X^n * M rem P M message P polynomial crc R : crc calculated.
T(x) = x^n * M(x) + R(x) property: T rem P = 0
createString
public static byte[] createString(String str)
throws IOException
Return a Arbitrary length binary string
First 4 bytes are the length of the string, msb first (not
including the length itself). The following "length" bytes are
the string value. There are no terminating null characters.
getMpInt
public static byte[] getMpInt(int offset,
byte[] byteArray)
throws IOException
Return the mp-int at the position offset in the data
First 2 bytes are the number of bits in the integer, msb first
(for example, the value 0x00012345 would have 17 bits). The
value zero has zero bits. It is permissible that the number of
bits be larger than the real number of bits.
The number of bits is followed by (bits + 7) / 8 bytes of binary
data, msb first, giving the value of the integer.
getNotZeroRandomByte
public static byte getNotZeroRandomByte()
getString
public static String getString(int offset,
byte[] byteArray)
throws IOException
return the strint at the position offset in the data
First 4 bytes are the length of the string, msb first (not
including the length itself). The following "length" bytes are
the string value. There are no terminating null characters.