异或加密算法

271 阅读1分钟

//异或加密算法

  function jiami(text){        
     var last = '';
    for(let i=0;i<text.length;i++){
      var text2 = text.charCodeAt(i)^64;
      last+=String.fromCharCode(text2);
    }
    return last;
  }
  let yihuotext = jiami(jiamitext);
  let yihuocode = encodeURIComponent(yihuotext);  //转成utf-8编码格式
浏览器就给我们提供了一个方法,也就是encodeURI/encodeURIComponent方法。这个方法会讲非英文字符(这里考虑下,为什么是非英文字符?)先转为UTF8的字节码,然后前面加个%进行拼接,所以我们将汉字"中"转义下便得到了"%E4%B8%AD".
想要解析回来应该怎么做哪?用decodeURI/decodeURIComponent就可以了