Skip to content

Instantly share code, notes, and snippets.

/js_to_py.py Secret

Created October 9, 2017 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/420c233004e1dbfbd98fe543a2d3ad15 to your computer and use it in GitHub Desktop.
Save anonymous/420c233004e1dbfbd98fe543a2d3ad15 to your computer and use it in GitHub Desktop.
#-*- coding=utf-8 -*-
import execjs
js="""
function utf8to16(str) {
var out, i, len, c;
var char2, char3;
out = "";
len = str.length;
i = 0;
while (i < len) {
c = str.charCodeAt(i++);
switch (c >> 4) {
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
// 0xxxxxxx
out += str.charAt(i - 1);
break;
case 12: case 13:
// 110x xxxx 10xx xxxx
char2 = str.charCodeAt(i++);
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2 = str.charCodeAt(i++);
char3 = str.charCodeAt(i++);
out += String.fromCharCode(((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
break;
}
}
return out;
}
function tochar(text) {
text = text.split("·");
var str = '';
var char='';
for (var i = 0, len = text.length; i < len; ++i) {
text[i] = text[i].substr(1);
text[i] = text[i].substring(0, text[i].length - 1);
str += String.fromCharCode(text[i]);
}
char=utf8to16(str);
return char;
}
"""
text="52297·61356·11868·62314·51679·41594·12321·21896·91661·62294·01438·51845·12308·51567·21864·7468·12335·61597·31691·22328·61750·61738·82280·11847·91732·82298·01739·71515·8460·1650·0461·7843·4976·51209·51055·8466·0684·51144·71059·61183·71014·91142·2468·0500·6489·2494·0550·7465·9728·5683·4556·8503·6489·1800·4461·0881·1505·7543·7528·0462·7654·8659·6676·1469·4677·9727·0830·9453·7561·9565·8509·0701·8882·3469·41090·11072·01184"
ctx=execjs.compile(js)
print ctx.call('tochar',text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment