Java 简单的加密解密算法 , 使用异或运算
实例 1:
Package cn.std.util; import java.nio.charset.charset; classe publique deencode {private static final string key0 = "fecoi () * & <mncxzpkl"; private static charse charset = charset.forname ("utf-8"); private static static byte [] keybytes = key0.getbytes (charset); public static byte (String Encotes = Key0.getBytes (charset); public static ultre (String Encotes = Key0.getBytes (Charset); Public Static STRINCE (STRING ENCOTES = Key0.getBytes (Charset); Public Strat 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 stating Decode Decode (string dec) {par [] e = e = e = e = e = e = e = e = b); 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 natic Main (string) Droite "; 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 result = ""; string temp = ""; for (int i = 0, j = 0; i <str.length (); i ++, j ++) {if (j == s.Length ())) j = 0; snnum [i] = str.charat (i) ^ sn.charat (j);} pour (int k = 0; k <str.length (); k ++) {if (snnum [k] <10) {temp = "00" + snnum [k];} else{if(snNum[k]<100){temp="0"+snNum[k];}}result+=temp;}return result;}public static String getEncrypt(String str){String sn="ziyu";//密钥char[] snNum=new char[str.length()/3];String result="";for (int 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.Carat (j));} pour (int (int (inrut k = 0; k <str.length () / 3; k ++) {résultat + = snnum [k];} Retour Result;}}总结
以上就是本文关于 Java 使用异或运算实现简单的加密解密算法实例代码的全部内容 , 希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题 , 如有不足之处 , 欢迎留言指出。感谢朋友们对本站的支持!