Python 字符串 所有用过 Python (2&3)的人应该都看过下面两行错误信息: UnicodeEncodeError: 'ascii' codec can't encode cha
贴吧:
python作者:
朦胧七夜 2016-04-22 11:11 回复:耳闻JAVA吧大神把QQ协议玩烂了,小弟特地到此请教~~ 刚才楼被吞了?
TEA这个类还没发上来..
public class TEA {
// if use 16 times , modify decrypt_group(byte[]) to sum = delta << 4;
public static byte[] encrypt(byte[] data, byte[] key) {
int data_len = data.length; // 锟斤拷莸某锟斤拷锟?
if (data_len == 0) {
return new byte[] {};
}
TEA t = new TEA();
if (!t.setKey(key)) {
return new byte[] {};
}
int group_len = 8;
int residues = data_len % group_len;
int dlen = data_len - residues;
int result_len = data_len + 1;
if (residues > 0) {
result_len += group_len - residues;
}
byte[] result = new byte[result_len];
result[0] = (byte)residues;
byte[] plain = new byte[group_len];
byte[] enc = new byte[group_len];
for (int i = 0; i < dlen; i += group_len) {
for (int j = 0; j < group_len; j++) {
plain[j] = data[i + j];
}
enc = t.encrypt_group(plain);
for (int k = 0; k < group_len; k++) {
result[i + k + 1] = enc[k];
}
}
if (residues > 0) {
for (int j = 0; j < residues; j++) {
plain[j] = data[dlen + j];
}
int padding = group_len - residues;
for (int j = 0; j < padding; j++) {
plain[residues + j] = (byte)0x00;
}
enc = t.encrypt_group(plain);
for (int k = 0; k < group_len; k++) {
result[dlen + k + 1] = enc[k];
}
}
return result;
}
public static byte[] decrypt(byte[] data, byte[] key) {
int group_len = 8;
if (data.length % group_len != 1) {
return new byte[] {};
}
TEA t = new TEA();
if (!t.setKey(key)) {
return new byte[] {};
}
int data_len = data.length - 1, dlen;
int residues = (int)(data[0]);
if (residues > 0) {
dlen = data_len - group_len;
} else {
dlen = data_len;
}
byte[] result = new byte[dlen + residues];
byte[] dec = new byte[group_len];
byte[] enc = new byte[group_len];
for (int i = 0; i < dlen; i += group_len) {
for (int j = 0; j < group_len; j++) {
enc[j] = data[i + j + 1];
}
dec = t.decrypt_group(enc);
for (int k = 0; k < group_len; k++) {
result[i + k] = dec[k];
}
}
if (residues > 0) {
for (int j = 0; j < group_len; j++) {
enc[j] = data[dlen + j + 1];
}
dec = t.decrypt_group(enc);
for (int k = 0; k < residues; k++) {
result[dlen + k] = dec[k];
}
}
return result;
}
贴吧:
java作者:
airgetbook 2013-12-17 12:50 锟截革拷锟斤拷【达摩!】来!能说会道的你们来给我讲讲达摩武学到 楼主 我就问你一句话 是不是太极的 要不是太极的 我就A游戏了 继续去坑我的FIFA ONLEN3
贴吧:
九阴作者:
巨神神坑 2015-12-03 15:38