Created
August 16, 2026 02:33
-
-
Save theMackabu/7e944110affda8107df8245dd3f1cbba to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const e = new TextEncoder(); | |
| const d = new TextDecoder(); | |
| function NaNcode(string) { | |
| const encoded = Array.from(e.encode(string)); | |
| encoded.unshift(0, 0, 0, 0, 0, 0); | |
| while (encoded.length % 6) encoded.push(0); | |
| const bytes = []; | |
| let i = 0; | |
| while (encoded.length) { | |
| bytes.push(encoded.shift()); | |
| i++; | |
| if (!(i % 6)) bytes.push(248, 127); | |
| } | |
| return Array.from(new Float64Array(new Uint8Array(bytes).buffer)); | |
| } | |
| function unNaNcode(NaNs) { | |
| const raw = new Uint8Array(new Float64Array(NaNs).buffer); | |
| let count = 0; | |
| for (let i = 0; i < raw.length; i++) { | |
| if (i % 8 < 6 && raw[i] !== 0) count++; | |
| } | |
| const bytes = new Uint8Array(count); | |
| let j = 0; | |
| for (let i = 0; i < raw.length; i++) { | |
| if (i % 8 < 6 && raw[i] !== 0) bytes[j++] = raw[i]; | |
| } | |
| return d.decode(bytes); | |
| } | |
| const NaNcoded = NaNcode('Hello, World! :D'); | |
| console.log(NaNcoded, unNaNcode(NaNcoded)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment