Java 简单的加密解密算法 使用异或运算 使用异或运算
实例 1 :
paquete cn.std.util; import java.nio.charset.charset; public class deencode {private static final string key0 = "feCoi ()*& <mncxzpkl"; private static final charset charset = charset.forname ("utf-8"); byte estial privado [] keybytes = clave 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 strat static decode (string decod) dec.getBytes (charset); byte [] dee = e; for (int i = 0, size = e.length; i <size; i ++) {for (byte keyBytes0: keyBytes) {e [i] = (byte) (dee [i]^keybytes0);} return New string (e);} public static void main (string [string [string) right "; String enc = encode (s); string dec = decode (enc); system.out.println (enc); system.out.println (dec);}}实例 2
public static string setEnCrypt (string str) {String sn = "ziyu"; // 密钥 int [] snnum = new int [str.length ()]; string dult dult = ""; string temp = ""; for (int i = 0, j = 0; i <str.length (); i ++, j ++) {if (j == sn.length ()) j = 0; snnum [i] = str.charat (i)^sn.charat (j);} para (int k = 0; k <str.length (); k ++) {if (snnum [k] <10) {temp = "00"+snnum [k];}; else {if (snnum [k] <100) {temp = "0"+snnum [k];}} resultado+= temp;} return resultado;} public static string getenCrypt (String str) {String sn = "ziyu"; // 密钥 char [] snnum = new char [str.lengther i=0,j=0;i<str.length()/3;i++,j++){if(j==sn.length()) j=0;int n=Integer.parseint(str.substring(i*3,i*3+3));snNum[i]=(char)((char)n^sn.charAt(j));}for (int k = 0; k <str.length ()/3; k ++) {result+= snnum [k];} return resultado;}}总结
以上就是本文关于 java 使用异或运算实现简单的加密解密算法实例代码的全部内容 , 希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题 如有不足之处 欢迎留言指出。感谢朋友们对本站的支持! 欢迎留言指出。感谢朋友们对本站的支持!