简易版加密解密

/** 加密:Base64 + 自定义扰乱 */
export function encrypt(text: string): string {
  const base64 = btoa(encodeURIComponent(text))
  return base64
    .split('')
    .map((c, i) => i % 2 === 0 ? String.fromCharCode(c.charCodeAt(0) + 1) : c)
    .reverse()
    .join('')
}

/** 解密:逆向扰乱 + Base64 */
export function decrypt(text: string): string {
  const reversed = text.split('').reverse()
  const restored = reversed
    .map((c, i) => i % 2 === 0 ? String.fromCharCode(c.charCodeAt(0) - 1) : c)
    .join('')
  return decodeURIComponent(atob(restored))
}

简易版加密解密
https://blog.fullsize.cn/2025/06/25/notion/jian-yi-ban-jia-mi-jie-mi/
作者
fullsize
发布于
2025年6月25日
许可协议