import Java.io.bytearray output stream;
公共类测试{
privatestaticstringhexstring=' 0123456789 abcdef abcdef ';
//privatestaticstringhexstring=' 0123456789 abcdef abcdef ';
//*
publicstaticvoidmain (字符串敏感招牌args )。
byte敏感招牌bytes=msg.getBytes (;
转换//hex代码
for(byteb:bytes ) {
sb.append(integer.toHEXstring ) b0x800 ).substring(1);
}
//转换后的代码为c7d7a3acc4e3bac3
msg=sb.toString (;
//再次转换为字符串
//system.out.println(msg;
}
//hex代码转换为字符串
publicstaticstringdecode (字符串字节) {
bytes=bytes.toUpperCase (;
//将每个2位的十六进制整数组装成一个字节
for(intI=0; i bytes.length (; i =2)
BAOS.write((hexstring.indexof ) bytes.charat(I ) )4| hex string.index of (bytes.charat ) I1 ) ) );
返回新字符串(baos.to bytearray );
}
}