调用mac方法的问题?求救
package com.test;public class Test {
public static byte[] getMac(byte[] dt, int mlen) {
int n, k, len, ilen;
// original input String length
len = dt.length;
// 原始串和mac长度的余数
k = len % mlen;
//
n = mlen - k;
ilen = len + n;
byte[] bt = new byte;
for (int i = 0; i < len; i++) {
dt = (byte) (dt > 0x00 ? dt : dt + 256);
bt = dt;
}
bt = 127;
byte bo[] = new byte;
for (int i = 0; i < ilen;) {
for (int j = 0; j < mlen; j++) {
bo ^= bt;
i++;
}
}
for (int i = 0; i < mlen; i++) {
// 如果遇到\r \n
if ((bo >= 0x00 ? bo : bo + 256) >= 0x80) { // "\r"
bo ^= 0x80;
}
if (bo == 0x0d) { // "\r"
bo = 0x4d;
}
if (bo == 0x0a) { // "\n"
bo = 0x4a;
}
if (bo == 0x3a) { // ":"
bo = 0x7a;
}
if (bo == 0x7c) { // "|"
bo = 0x3c;
}
if (bo == 0x00) { // "0"
bo = 0x40;
}
}
return bo;
}
/** * 将String转为byte数组 */
public static byte[] stringToBytes(String s, int length) {
while (s.getBytes
().length < length) {
s += " ";
}
return s.getBytes();
}
public static void main(String[] args) {
String test = "90|EPA0FE00000|20130425|040136|05|461800|EPA0FE2|0203|130409011231|3004015971|50.40|";
byte[] testByte = stringToBytes(test,85);
byte[] mac = getMac(testByte,8);
System.out.println(mac);
}
}
上面main函数有问题吗?
一组字符串校验后,生产什么结果是什么呢? 请高手 帮忙回复。 没看懂你的意思,感觉这些所有的都有函数的
页:
[1]