乐趣区

关于javascript:如何对字符串进行加密解密

// 对字符串加密
export function decodeStr(code) {let c = String.fromCharCode(code.charCodeAt(0) + code.length);
  for (let i = 1, len = code.length; i < len; i++) {c += String.fromCharCode(code.charCodeAt(i) + code.charCodeAt(i - 1));
  }
  return decodeURI(c);
}

// 字符串进行解密
export function uncodeStr(code) {code = decodeURIComponent(code);
  let c = String.fromCharCode(code.charCodeAt(0) - code.length);
  for (let i = 1, len = code.length; i < len; i++) {c += String.fromCharCode(code.charCodeAt(i) - c.charCodeAt(i - 1));
  }
  return c;
}
退出移动版