import java.nio.charset.Charset;
public class DeEnCode {
private static final String key0 = "FECOI()*&<MNCXZPKL";
private static final Charset charset = Charset.forName("UTF-8");
private static byte[] keyBytes = key0.getBytes(charset);
public static String encode(String enc){
byte[] b = enc.getBytes(charset);
for(int i=0,size=b.length;i<size;i++){
for(byte keyBytes0:keyBytes){
b[i] = (byte) (b[i]^keyBytes0);
}
}
return new String(b);
}
public static String decode(String s){
byte[] e = s.getBytes(charset);
byte[] d = e;
for(int i=0,size=e.length;i<size;i++){
for(byte k:keyBytes){
e[i] = (byte) (d[i]^k);
}
}
return new String(e);
}
public static void main(String[] args) {
String s="str";
String enc = encode(s);
String dec = decode(enc);
System.out.println(enc);
System.out.println(dec);
}
}
java 加解密
最新推荐文章于 2024-08-02 07:30:00 发布