Skip to content

Commit e5a68ec

Browse files
committed
V2 Reimplementation & better content.
1 parent bdcce99 commit e5a68ec

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

README.md

9.27 KB
Binary file not shown.

phantom-script.js

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* Encoder
77
*/
88
var encode = function(payload){
9-
109
var convert2Ascii = function(text){
1110
return Array
1211
.from(text)
@@ -19,53 +18,50 @@
1918
}
2019
else
2120
return char;
22-
});
23-
};
24-
25-
var mapping = function(char){
26-
if (char > 8) char+= 2;
27-
if (char > 31) char+= 95;
28-
return char;
29-
};
30-
31-
var mapCharacters = function(text){
32-
return text
33-
.split('')
34-
.map(x=>x.charCodeAt())
35-
.map(x=>{
36-
var low = mapping( x & 0x1F);
37-
var high = mapping( x >> 5 );
38-
return String.fromCharCode(high, low);
3921
})
4022
.join('');
4123
};
4224

43-
return mapCharacters( convert2Ascii(payload).join('') );
25+
return convert2Ascii(payload)
26+
.split('')
27+
// Adds 9th bit, then slices it off for zero padding.
28+
.map(x=>(0x100 | x.charCodeAt()).toString(2).slice(1))
29+
.join('')
30+
.split('')
31+
.map(x=>String.fromCharCode(x*0xFEFF))
32+
.join('');
4433
};
4534

4635

47-
4836
/**
4937
* Decoder
5038
*/
5139
var decode = function(val){
52-
return val
53-
.split('')
54-
.map(x=>x.charCodeAt())
55-
.filter( x=> (x <= 8) || (x >= 11 && x <= 31) || ( x >= 127 && x <= 159) )
56-
.map(x=>{
57-
if (x > 126) x-= 95;
58-
if (x > 10) x-=2;
59-
return x;
60-
})
61-
.reduce((x,cur,i,v)=> i%2? x + String.fromCharCode((v[i-1] << 5) + cur) : x,'');
40+
return Array
41+
.from(val)
42+
.map(x=>x.charCodeAt() && 1 )
43+
.join('')
44+
.match(/.{8}/g)
45+
.map(function(c){
46+
return String.fromCharCode(parseInt(c,2))
47+
})
48+
.join('');
49+
};
50+
51+
52+
/**
53+
* DecodeEval - Actually eval the decoded payload.
54+
*/
55+
var decodeEval = function(code){
56+
[]["filter"]["constructor"]( decode(code) )();
6257
};
6358

6459

6560

6661
var phantomScript = {
6762
encode: encode,
68-
decode: decode
63+
decode: decode,
64+
decodeEval: decodeEval
6965
}
7066

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

0 commit comments

Comments
 (0)