一個非常簡單的私有加密演算法

barbin發表於2008-12-04
[code="java"][/code]
public class ZYGEncrypt {
private static final byte[] enkeystore = {
0x08, 0x02, 0x0b, 0x0c, 0x01, 0x0a, 0x00, 0x0d, 0x07, 0x03, 0x0e,
0x05, 0x0f, 0x06, 0x04, 0x09
};
private static final byte[] dekeystore = {
0x06, 0x04, 0x01, 0x09, 0x0e, 0x0b, 0x0d, 0x08, 0x00, 0x0f, 0x05,
0x02, 0x03, 0x07, 0x0a, 0x0c
};

public static byte[] encode(byte[] data) {
byte[] result = new byte[data.length];

for (int i = 0; i < data.length; i++) {
result[i] += (enkeystore[(data[i] >>> 4) & 0x0F] << 4);
result[i] += (enkeystore[data[i] & 0x0F]);
}

return result;
}

public static byte[] decode(byte[] data) {
byte[] result = new byte[data.length];

for (int i = 0; i < data.length; i++) {
result[i] += (dekeystore[(data[i] >>> 4) & 0x0F] << 4);
result[i] += (dekeystore[data[i] & 0x0F]);
}

return result;
}

public static void main(String[] args) {
String data = "1";
byte[] databyte = ZYGEncrypt.encode(data.getBytes());
byte[] resultdata = ZYGEncrypt.decode(databyte);
System.out.println(data);
System.out.println(new String(resultdata));
}

相關文章