Skip to content

Instantly share code, notes, and snippets.

@alexcmgit
Created January 3, 2023 04:24
Show Gist options
  • Save alexcmgit/02446ed461fad3c8184ef5aaa4396eda to your computer and use it in GitHub Desktop.
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
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