/*
某电话公司的电话数据是经过加密后传送的,其加密规则如下:对数据中的每个字节取反,再将字节的第1位和第8位交换,第2位和第7位交换。
1、 请写出这个加密程序和相应的解密程序。
2、 自定义一个类,并使用以上加密程序对类进行加密,然后自定义一个类加载器运行加密后的类。
*/
import java.io.*;
public class PhoneDemo{
public static void main(String args[])
{
FileInputStream in = new FileInputStream("My.class");
FileOutputStream out = new FileOutputStream("NewMy.class");
int ch = 0;
while((ch = in.read())!=-1)
{
int encryptNum = encrypt(ch);
out.write(encryptNum);
}
in.close();
out.close();
}
public static int encrypt(int ch)
{
int reverse = ch^-1;
int ch8 = (reverse&128)>>7;
int ch7 = (reverse&64)>>5;
int ch2 = (reverse&2)<<5;
int ch1 = (reverse&1)<<7;
int i = reverse&60;
return i|ch8|ch7|ch2|ch1;
}
}
public class My
{
public void run()
{
System.out.println("haha");
}
}
自定义class类加载器稍后......