Last active
December 3, 2021 01:49
-
-
Save mandel59/ee905406860f3155f4a93ac35cd6c0cf to your computer and use it in GitHub Desktop.
https://twitter.com/needle/status/1466336299703422977 の文字化けを解読する時に使ったスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* range(a, b) { | |
for (let i = a; i <= b; i++) { | |
yield i; | |
} | |
} | |
function* decode(s) { | |
const b = Buffer.from(s, "latin1"); | |
if (b.length === 1) { | |
for (const i of range(0x80, 0x9f)) { | |
for (const j of range(0x80, 0x9f)) { | |
yield [b[0], i, j]; | |
} | |
} | |
} else if (b.length === 2) { | |
for (const i of range(0x80, 0x9f)) { | |
yield [b[0], i, b[1]]; | |
yield [b[0], b[1], i]; | |
} | |
} | |
} | |
const d = "å»ä¸ãªãã³ã°å´" | |
.match(/[\x00-\x7f]|[\xc0-\xff][\x80-\xbf]*/g) | |
.map(s => Array.from(decode(s)).map(a => Buffer.from(a).toString()).join("")); | |
for (const i of d) { | |
console.log(i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment