|
import java.lang.*;
import java.io.*;
class jiami{
final String sKey="thisiskey";
private String sdata="welcomeyou";
public jiami(String tt){
sdata=tt;
}
public String getdata(){
return sdata;
}
public String jia(){
char[] tmpdata=sdata.toCharArray();
int i,j;
for (i=0;i<sdata.length();i++){
for (j=0;j<sKey.length();j++){
tmpdata=(char)(sdata.charAt(i) ^ sKey.charAt(j));
}
}
sdata=new String(tmpdata);
return new String(tmpdata);
}
public String jie(){
char[] tmpdata=sdata.toCharArray();
int i,j;
for (i=0;i<sdata.length();i++){
for (j=0;j<sKey.length();j++){
tmpdata=(char)(sdata.charAt(i) ^ sKey.charAt(j));
}
}
sdata=new String(tmpdata);
return new String(tmpdata);
}
public static void main(String arg[]){
jiami tmpdata1=new jiami("thisisjgx");
// jiami tttt=new jiami("thismyfriend");
System.out.println(tmpdata1.jia());
System.out.println("start:"+tmpdata1.getdata());
/** System.out.println("is jiahou:"+tmpdata1.getdata());
System.out.println("is jiemi:"+tmpdata1.jie());
*/
}
}
上面的程序现在有一个问题是:每个加解密后都会有两个字节的偏移.把相邻的数据也影响了.不知错在哪里了.希望有人能指点一下 |
|