aemkei / jsfuck

Write any JavaScript with 6 Characters: []()!+
jsfuck.com
Do What The F*ck You Want To Public License
8.16k stars 674 forks source link

Another alternative #4

Closed sylvainpolletvillard closed 11 years ago

sylvainpolletvillard commented 11 years ago

Hi there,

I just discovered this project after I made my own implementation of a Javascript compiler into "six characters". It's interesting to compare our implementations, which are quite close actually.

The main difference is for the encode script. Here is mine :

app.encode = function(input){
        var charcodes = [];
        for(var c=0; c<input.length; c++){
            charcodes.push( app.convertInt( input.charCodeAt(c) ) );
        }
        var out = "[]+" + charcodes.join("+"+app.convertTable["f"]+"+");
        out = "[]+(" + out + ")["+_("split")+"]("+app.convertTable["f"]+")";
        out = _("return ") + "+" + app.convertTable["String"] + "+" + _(".fromCharCode(") + "+(" + out +")+" + _(')');
        out = app.eval(out);
        out = app.eval(out);
        return out;
    };

So i just convert all the input into charCodes and then interprate them with String.fromCharCode(c1,c2,c3,c4...)

For small scripts, your encoder makes file size smaller, but the performance and the script size is far better for large scripts with my approach.

Here is my version: http://syllab.fr/projets/experiments/sixcharsjs/ and the source : http://syllab.fr/projets/experiments/sixcharsjs/js/main.js

Unfortunately I wrote all the explainations in French.

aemkei commented 11 years ago

Nice one and way faster! Maybe we can find a way to combine them...