|
|
发表于 2025-5-31 09:51:23
|
显示全部楼层
那应该是作者自己设计的编码表 ,貌似不是单纯的运算转换
字符A-Z是从U+e0110开始的26个
字符a-z是从U+e0151开始的26个
空格是U+e0110
换行是U+fe0a
....
其实不一定要按照那里的作者那样 ,也可以自己设计编码表或转换方式 ,只要找到并利用那些的不显示的字符就行了
例如下面的 ,保存为utf8编码的html ,然后用支持es6标准的浏览器打开
(U+e0000至U+e00ff好像是不显示的 ,通过直接将字符看成单字节然后加上0xe0000来实现的)
- <!DOCTYPE html>
- <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
- <head><script type="text/javascript" >
- function the_nil_coding(){
- this.chr=[];
- for(var i=0xe0000;i<=0xe00ff;i++){
- this.chr.push(String.fromCodePoint(i));
- }
- this.encode=function(str,pre){
- var rt=[];
- if(pre){
- rt.push(pre);
- }else{
- rt.push('N');
- }
- rt.push(String.fromCodePoint(0xe0100));
- if(!str||!str.length)return rt.join('');
- var c=str.length;
- for(var i=0;i<c;i++){
- var p=str.charCodeAt(i);
- var h=p>>>8;
- var l=p&0xff;
- rt.push(this.chr[h]);
- rt.push(this.chr[l]);
- }
- return rt.join('');
- }
- this.decode=function(str){
- var k=0,j=0,rt=[];
- if(!str||!str.length)return rt.join('');
- for(let i of str){
- var p=i.codePointAt(0);
- if(p==0xe0100)k=1;
- if(k){
- if(p>=0xe0000&&p<0xe0100){
- j++;
- if(j==2){
- var l=p-0xe0000;
- rt.push(String.fromCharCode(h+l));
- h=0,l=0,j=0;
- }else{
- var h=(p-0xe0000)<<8;
- }
- }}}
- return rt.join('');
- }
- }
- window.onload=function(){
- var nil_coding=new the_nil_coding();
- document.getElementById('ec').onclick=function(){
- document.getElementById('rs').value='';
- var t=nil_coding.encode(
- document.getElementById('ip').value,document.getElementById('pf').value);
- document.getElementById('rs').value=t;};
- document.getElementById('dc').onclick=function(){
- document.getElementById('rs').value='';
- var t=nil_coding.decode(document.getElementById('ip').value);
- document.getElementById('rs').value=t;}
- document.getElementById('cli').onclick=function(){
- document.getElementById('ip').value='';}
- document.getElementById('clr').onclick=function(){
- document.getElementById('rs').value='';}
- document.getElementById('cla').onclick=function(){
- document.getElementById('ip').value='';
- document.getElementById('rs').value='';}
- }
- </script></head>
- <body>
- <label>input</label><input id='cli' type='button' value='clear'/></br>
- <textarea id='ip' style="width:450px;height:200px;border:2px solid;"></textarea></br></br>
- <label>prefix:</label><input id='pf' type="text" value="N"/>
- <input id='ec' type='button' value='encode input'/>
- <input id='dc' type='button' value='decode input'/>
- <input id='cla' type='button' value='clear all'/>
- </br></br>
- <textarea id='rs' style="width:450px;height:200px;border:2px solid;"></textarea></br>
- <label>result</label><input id='clr' type='button' value='clear'/></br>
- </body></html>
复制代码 |
|