System information

Appendix D. JAVA Example Code
D-6
/**
* Calculates the signature for a byte.
*/
static char calcSigForByte(byte buff, char seed)
{
char rtn = (char)seed;
char j = rtn;
rtn = (char)((rtn << 1) & (char)0x01FF);
if(rtn >= (int)0x100)
rtn++;
rtn = (char)(((rtn + (j >> 8) + buff) & (char)0xFF) | (j << 8));
return rtn;
} // calcSigForByte
/**
* calculates the signature nullifier
*/
static char calcSigNullifier(char sig)
{
//calculate the value for the most significant byte. Then run this
//value through the signature algorithm using the specified
//signature as seed. The calculation is designed to cause the
//least significant byte in the signature to become zero.
char new_seed = (char)((sig << 1) & (char)0x1FF);
byte[] null1 = new byte[1];
int new_sig = sig;
if(new_seed >= 0x0100)
new_seed++;
null1[0] = (byte)((char)0x0100 - (new_seed + (sig >> 8)));
new_sig = calcSigFor(null1,1,sig);
//now perform the same calculation for the most significant byte
//in the signature. This time we will use the signature that was
//calculated using the first null byte
char null2;
new_seed = (char)((new_sig << 1) & (char)0x01FF);
if(new_seed >= 0x0100)
new_seed++;
null2 = (char)((char)0x0100 - (new_seed + (char)(new_sig >> 8)));
//now form the return value placing null one in the most
//significant byte location
char rtn = (char)null1[0];
rtn <<= 8;
rtn += null2;
return rtn;
} // calcSigNullifier
/**
* Sends and quotes the pakbus packet
*/
public static void SendPb()
{
try
{
byte[] frame = out_packet.to_link_state_packet();