[*Encode把long数组按顺序拆成byte数组,因为java的long类型是64bit的,
只拆低32bit,以适应原始C实现的用途
*/
private void Encode (byte[] output, long[] input, int len) {
int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (byte)(input & 0xffL);
output[j + 1] = (byte)((input >>>8) & 0xffL);
output[j + 2] = (byte)((input >>>16) & 0xffL);
output[j + 3] = (byte)((input >>>24) & 0xffL);
}
}
/*Decode把byte数组按顺序合成成long数组,因为java的long类型是64bit的,
只合成低32bit,高32bit清零,以适应原始C实现的用途
*/
private void Decode (long[] output, byte[] input, int len) {
int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output = b2iu(input[j]) |
(b2iu(input[j + 1]) << 8) |
(b2iu(input[j + 2]) << 16) |
(b2iu(input[j + 3]) << 24);
return;
}
/*
b2iu是我写的一个把byte按照不考虑正负号的原则的"升位"程序,因为java没有unsigned运算
*/
public static long b2iu(byte b) {
return b < 0 ? b & 0x7F + 128 : b;
}
/*byteHEX(),用来把一个byte类型的数转换成十六进制的ASCII表示,
因为java中的byte的toString无法实现这一点,我们又没有C语言中的
sprintf(outbuf,"%02X",ib)
*/
public static String byteHEX(byte ib) {
char[] Digit = { '0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F' };
char [] ob = new char[2];
ob[0] = Digit[(ib >>>4) & 0X0F];
ob[1] = Digit[ib & 0X0F];
String s = new String(ob);
return s;
}
public static void main(String args[]) {
keyBean m = new keyBean();
if
(Array.getLength(args) == 0)
{ //如果没有参数,执行标准的Test Suite
System.out.println("keyBean Test suite:");
System.out.print(m.getkeyBeanofStr("woaiguqianmeng"));
}
else
System.out.println("keyBean(" + args[0] + ")=" + m.getkeyBeanofStr(args[0]));