Java 简单的加密解密算法 , 使用异或运算
实例 1:
pacote cn.std.util; importar java.nio.charset.charset; public class DeEncode {private estático final string key0 = "fEcoi ()*& <mncxzpkl"; private estático final do charset = charset.forname ("utf-8"); private static byte; keybytes = keytes = keys = keys = keyset.Forname ("utf-8); Enc) {byte [] b = Enc.getBytes (charset); para (int i = 0, size = b.Length; i <tamanho; i ++) {for (byte keybytes0: keybytes) {b [i] = (byte) (b [i]^keyTes0);}}} (b) (b) = (b) (b) (b) (b [i]^keyTes0);}}} (b) string (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 void main(String[] args) {String s="you are à direita "; string ENC = Encode (s); String dec = decodge (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 = ""; para (int i = 0, j = 0; i <str.length (); i ++, j ++) {se (j = 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.l)/3]/3]; 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); k = 0; k <str.length ()/3; k ++) {resultado+= snnum [k];} RESULTO DE RETURN;}}总结
以上就是本文关于 Java 使用异或运算实现简单的加密解密算法实例代码的全部内容 , 希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题 , 如有不足之处 , 欢迎留言指出。感谢朋友们对本站的支持!