Created
September 16, 2018 11:34
-
-
Save sylvainpolletvillard/9b51a4bcc4e542d382b29fa2dfdc0638 to your computer and use it in GitHub Desktop.
basic base 5 to utf-16 converter for 5chars.js. Probably useless
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
{ | |
let chars = '+=[]_'; | |
let range = 6; // 5^6 < 65535 < 5^7 | |
function base5compress(input){ | |
let out=""; | |
for(let i=0; i<input.length; i+=range){ | |
let part = input.slice(i, i+range).split('').reverse(); | |
let charcode = part.reduce((acc, c) => chars.length*acc + chars.indexOf(c), 0) | |
out += String.fromCharCode(charcode) | |
} | |
return out; | |
} | |
function base5parse(input){ | |
let out =""; | |
for(let i=0; i<input.length; i++){ | |
let code = input.charCodeAt(i); | |
for(let j=1; j<=range; j++){ | |
out += chars[code % chars.length]; | |
code = Math.floor( code / chars.length) | |
} | |
} | |
return out; | |
} | |
console.log("Compressed: ",base5compress(input).length); | |
eval(base5parse(base5compress(input))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment