/*** * * * * * * */ var _Base64 = { // let _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode:function(e) { // function bsencodeURI(e){ var t = ""; var n, r, i, s, o, u, a; var f = 0; // e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t += this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) // t += _keyStr.charAt(s) + _keyStr.charAt(o) + _keyStr.charAt(u) + _keyStr.charAt(a) } return t }, // } decode:function(e) { // function bsdecode(e){ // console.log("e", e, e.length) var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace('/[^A-Za-z0-9+/=]/g', "").toString() // console.log("e", e, e.length) while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); // console.log("s o u a", s, o, u, a) n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t += String.fromCharCode(r) } if (a != 64) { t += String.fromCharCode(i) } } // t = Base64._utf8_decode(t); // console.log('t',t) return t }, // } _utf8_encode: function(e) { e = e.replace(/rn/g, "n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function(e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } } async function loadedFun(type, len, uint32text){ const num = Math.ceil(len*4/(1024*64)); // console.log("loadedFun uint32text", len, uint32text, uint32text.length); let memory = new WebAssembly.Memory({initial: 3+num}); return fetch('/s/js/webc/wmjs/im.wasm').then(response=>response.arrayBuffer()) .then(bytes=>WebAssembly.instantiate(bytes)).then(result=>{ // console.log('fetch result', result); let exports = result.instance.exports; // memory.grow(1); let uint32 = new Uint32Array(exports.memory.buffer); uint32.set(uint32text); // console.log('uint32', uint32, uint32text.length, uint32text.byteLength); let len_u32 = exports.mix_fun(type, len, uint32); // console.log('mix_fun', uint32, len_u32); let uint8 = new Uint8Array(len_u32*4); for(let i = 0; i < len_u32; i++){ uint8[4*i] = uint32[i] & 0xff; uint8[4*i+1] = uint32[i] >> 8 & 0xff; uint8[4*i+2] = uint32[i] >> 16 & 0xff; uint8[4*i+3] = uint32[i] >> 24 & 0xff; } return uint8; }) } async function ed_fun(type, text){ const encoder = new TextEncoder('utf-8'); const decoder = new TextDecoder('utf-8'); if(type === 1){ const addstr = '____cinraw__'; let addText = text.trim()+addstr.trim(); // const uirtext = encodeURIComponent(addText); const uirtext = encoder.encode(addText); // console.log('uirtext', uirtext, uirtext.length); const len = uirtext.length; const len_add = len%16 ? 16 - len%16 : len%16; let enText = new Uint8Array(len+len_add); for(let i = 0; i < len; i++) enText[i] = uirtext[i]; for(let i = 0; i < len_add; i++) enText[i+len] = '_'.codePointAt(0); let uint32Text = new Uint32Array(enText.buffer, enText.byteOffset, enText.byteLength/4); // console.log('uint32Text', uint32Text, uint32Text.length, len+len_add); const len_u32 = (len+len_add)/4 return loadedFun(1, len_u32, uint32Text).then(res=>{ // console.log("charCodeAt", String.fromCharCode(128525)) // console.log("res", res, res.length); let eddata = String.fromCodePoint(...res); const len_eddata = eddata.length%3 ? 3 - eddata.length%3 : eddata.length%3; for(let i = 0; i < len_eddata; i++) eddata += '_' // console.log("endata", eddata, eddata.length) // return res // return btoa(eddata); return _Base64.encode(eddata) }) }else if(type === 0){ // const detext = atob(text).split('').map(c=>c.codePointAt(0)) // const detext = atob(text) const detext = _Base64.decode(text) // const detext = encoder.encode(text); const len_debs64 = detext.length; const len_add = len_debs64%16 ? 16 - len_debs64%16 : len_debs64%16; // console.log("detext", detext, len_debs64, len_add); const len_u = len_debs64+len_add const uint8Text = new Uint8Array(len_u); // for(let i = 0; i < len_debs64; i++) uint8Text[i] = detext[i]; for(let i = 0; i < len_debs64; i++) uint8Text[i] = detext[i].codePointAt(0); for(let i = 0; i < len_add; i++) uint8Text[i+len_debs64] = '_'.codePointAt(0); // console.log('decryp uint8Text', uint8Text, uint8Text.length); const uin32text = new Uint32Array(uint8Text.buffer, uint8Text.byteOffset, uint8Text.length/4); // console.log('len_u32 ',uin32text.length , len_debs64, len_add); return loadedFun(0, uin32text.length, uin32text).then(result=>{ const a = decoder.decode(result); // console.log('a', a) return decodeURIComponent(a) }) } }