aemkei/jsfuck

Why `escapeSequence()` treat characters whose charCodes is under 256 as ascii, not utf-16?

Closed this issue · 4 comments

In escapeSequence(),characters whose charCodes is under 256 will turn into ascii code.
However, it works well if we treat it as utf-16. Both "\141" and "\u0061" represent "a".

jsfuck/jsfuck.js

Lines 232 to 240 in 94c3835

function escapeSequence(c) {
var cc = c.charCodeAt(0);
if (cc < 256) {
return '\\' + cc.toString(8);
} else {
var cc16 = cc.toString(16);
return '\\u' + ('0000' + cc16).substring(cc16.length);
}
}

Is

if (cc < 256) { 
     return '\\' + cc.toString(8); 
} 

a necessary statement?

If it is not necessary, I remove it in #116

Although both work, this was added as the resulting jsfuck is shorter when representing ASCII chars using the ISO-8859-1 escape notation (\XXX (where XXX is 1–3 octal digits; range of 0–377)). See pull requests #93 and #88 :)

This was done to optimize the length of resulting code

Oh, I see. What a great work!