Skip to content

Commit

Permalink
V2 Reimplementation & better content.
Browse files Browse the repository at this point in the history
  • Loading branch information
jagracey committed Jun 3, 2016
1 parent bdcce99 commit e5a68ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
Binary file modified README.md
Binary file not shown.
58 changes: 27 additions & 31 deletions phantom-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Encoder
*/
var encode = function(payload){

var convert2Ascii = function(text){
return Array
.from(text)
Expand All @@ -19,53 +18,50 @@
}
else
return char;
});
};

var mapping = function(char){
if (char > 8) char+= 2;
if (char > 31) char+= 95;
return char;
};

var mapCharacters = function(text){
return text
.split('')
.map(x=>x.charCodeAt())
.map(x=>{
var low = mapping( x & 0x1F);
var high = mapping( x >> 5 );
return String.fromCharCode(high, low);
})
.join('');
};

return mapCharacters( convert2Ascii(payload).join('') );
return convert2Ascii(payload)
.split('')
// Adds 9th bit, then slices it off for zero padding.
.map(x=>(0x100 | x.charCodeAt()).toString(2).slice(1))
.join('')
.split('')
.map(x=>String.fromCharCode(x*0xFEFF))
.join('');
};



/**
* Decoder
*/
var decode = function(val){
return val
.split('')
.map(x=>x.charCodeAt())
.filter( x=> (x <= 8) || (x >= 11 && x <= 31) || ( x >= 127 && x <= 159) )
.map(x=>{
if (x > 126) x-= 95;
if (x > 10) x-=2;
return x;
})
.reduce((x,cur,i,v)=> i%2? x + String.fromCharCode((v[i-1] << 5) + cur) : x,'');
return Array
.from(val)
.map(x=>x.charCodeAt() && 1 )
.join('')
.match(/.{8}/g)
.map(function(c){
return String.fromCharCode(parseInt(c,2))
})
.join('');
};


/**
* DecodeEval - Actually eval the decoded payload.
*/
var decodeEval = function(code){
[]["filter"]["constructor"]( decode(code) )();
};



var phantomScript = {
encode: encode,
decode: decode
decode: decode,
decodeEval: decodeEval
}

typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = phantomScript :
Expand Down

0 comments on commit e5a68ec

Please sign in to comment.