public class Main1 { final static int MULTI_0 = 19; final static int MULTI_1 = 27; /** * 字符串加密算法 * */ public static void main(String[] args) { String t0 = "!@#$%!@#$%^&()_+HJkjk123j"; byte[] tb0 = t0.getBytes(); //加密的byte数组 byte[] temp = new byte[tb0.length]; for(int i = 0,len = tb0.length; i < len; i++){ temp[i] = (byte)(tb0[i] * MULTI_0); } //解密temp字节数组 byte[] tb1 = new byte[temp.length]; for(int i = 0,len = tb1.length; i < len; i++){ tb1[i] = (byte)(temp[i] * MULTI_1); } // 解密结果 System.out.println("原字符串:" + t0); System.out.println("加密后的字符串:" + new String(temp)); System.out.println("解密后的字符串:" + new String(tb1)); System.out.println("解密成功?--- " + t0.equals(new String(tb1))); } }?
PS:关键字:257,513,1025.... 2^n + 1