// 定义密钥 List skey = [8, 1, 2, 5, 4]; // 单个字符异或运算 String makecodeChar(String c, int key, int key2) { int charCode = c.codeUnitAt(0); charCode = (((charCode + key) ^ key2) ^ key) + 1; return String.fromCharCode(charCode); } // 单个字符解密 String cutcodeChar(String c, int key, int key2) { int charCode = c.codeUnitAt(0); charCode = (((charCode - 1) ^ key) ^ key2) - key; return String.fromCharCode(charCode); } // 加密 String makecode(String pstr, List pkey) { String pp = pstr; for (int i = 0; i < pp.length; i++) { pp = pp.replaceRange(i, i + 1, makecodeChar(pp[i], pkey[i % 5], pkey[(i + 18) % 5])); } return pp; } // 解密 void cutecode(String pstr, List pkey) { for (int i = 0; i < pstr.length; i++) { pstr = pstr.replaceRange(i, i + 1, cutcodeChar(pstr[i], pkey[i % 5], pkey[(i + 18) % 5])); } }