Created
January 3, 2023 04:24
-
-
Save alexcmgit/02446ed461fad3c8184ef5aaa4396eda to your computer and use it in GitHub Desktop.
Masking string to integer and unmask to string. wip, has bit limit and is not useful for large messages
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 bits = 8 | |
function mask(src) { | |
return Array.from(src).map(e => e.charCodeAt(0)).map((e, i) => e << (i * bits)).reduce((acc, e) => acc | e, 0) | |
} | |
function unmask(src) { | |
let i = 0 | |
const codes = [] | |
const b = (1 << bits) - 1 | |
while (src !== 0) { | |
console.log(src.toString(2)) | |
codes.push(src & b) | |
src = src >> bits | |
i++ | |
} | |
return codes.map(e => String.fromCharCode(e)).join('') | |
} | |
console.log(mask("v16.13.2")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment