Skip to content

Instantly share code, notes, and snippets.

@sylvainpolletvillard
Created September 16, 2018 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sylvainpolletvillard/9b51a4bcc4e542d382b29fa2dfdc0638 to your computer and use it in GitHub Desktop.
Save sylvainpolletvillard/9b51a4bcc4e542d382b29fa2dfdc0638 to your computer and use it in GitHub Desktop.
basic base 5 to utf-16 converter for 5chars.js. Probably useless
{
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