Java 简单的加密解密算法 , 使用异或运算
实例 1 :
package 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");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);} {b [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); {{{{{i]; kanan "; 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 (r = 0. j = 0; snnum [i] = str.charat (i)^sn.charat (j);} untuk (int k = 0; k <str.length (); k ++) {if (snnum [k] <10) {temp = "00"+snnum [k];} else {if (snnum [k] <100) {temp = "0"+snnum [k];}} hasil+= temp;} hasilnya;} string statis publik getEncrypt (string str) {string sn = "ziyu"; // 密钥 char [] snnum = baru char [str.length ()/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)); snnum [i] = (char) ((char) n^sn. k = 0; k <str.length ()/3; k ++) {result+= snnum [k];} hasil pengembalian;}}总结
以上就是本文关于 Java 使用异或运算实现简单的加密解密算法实例代码的全部内容 , 希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题 , 如有不足之处 , 欢迎留言指出。感谢朋友们对本站的支持!