0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-14 02:58:47 +00:00
OI-codes/Codeforces/1663/G/G.js

417 lines
11 KiB
JavaScript
Raw Normal View History

/*! JSFuck 0.5.0 - http://jsfuck.com */
const MIN = 32,
MAX = 126;
const SIMPLE = {
2022-06-01 01:45:41 +00:00
false: '![]',
true: '!![]',
undefined: '[][[]]',
NaN: '+[![]]',
Infinity: '+(+!+[]+(!+[]+[])[!+[]+!+[]+!+[]]+[+!+[]]+[+[]]+[+[]]+[+[]])', // +"1e1000"
};
const CONSTRUCTORS = {
2022-06-01 01:45:41 +00:00
Array: '[]',
Number: '(+[])',
String: '([]+[])',
Boolean: '(![])',
Function: '[]["flat"]',
RegExp: 'Function("return/"+false+"/")()',
Object: '[]["entries"]()',
};
const MAPPING = {
a: '(false+"")[1]',
b: '([]["entries"]()+"")[2]',
c: '([]["flat"]+"")[3]',
d: '(undefined+"")[2]',
e: '(true+"")[3]',
f: '(false+"")[0]',
2022-06-01 01:45:41 +00:00
g: '(false+[0]+String)[20]',
h: '(+(101))["to"+String["name"]](21)[1]',
2022-06-01 01:45:41 +00:00
i: '([false]+undefined)[10]',
j: '([]["entries"]()+"")[3]',
k: '(+(20))["to"+String["name"]](21)',
l: '(false+"")[2]',
m: '(Number+"")[11]',
n: '(undefined+"")[1]',
o: '(true+[]["flat"])[10]',
p: '(+(211))["to"+String["name"]](31)[1]',
q: '("")["fontcolor"]([0]+false+")[20]',
r: '(true+"")[1]',
s: '(false+"")[3]',
t: '(true+"")[0]',
u: '(undefined+"")[0]',
v: '(+(31))["to"+String["name"]](32)',
w: '(+(32))["to"+String["name"]](33)',
x: '(+(101))["to"+String["name"]](34)[1]',
2022-06-01 01:45:41 +00:00
y: '(NaN+[Infinity])[10]',
z: '(+(35))["to"+String["name"]](36)',
A: '(NaN+[]["entries"]())[11]',
2022-06-01 01:45:41 +00:00
B: '(+[]+Boolean)[10]',
C: 'Function("return escape")()(("")["italics"]())[2]',
D: 'Function("return escape")()([]["flat"])["slice"]("-1")',
E: '(RegExp+"")[12]',
2022-06-01 01:45:41 +00:00
F: '(+[]+Function)[10]',
G: '(false+Function("return Date")()())[30]',
H: null,
I: '(Infinity+"")[0]',
J: null,
K: null,
L: null,
M: '(true+Function("return Date")()())[30]',
N: '(NaN+"")[0]',
2022-06-01 01:45:41 +00:00
O: '(+[]+Object)[10]',
P: null,
Q: null,
2022-06-01 01:45:41 +00:00
R: '(+[]+RegExp)[10]',
S: '(+[]+String)[10]',
T: '(NaN+Function("return Date")()())[30]',
U: '(NaN+Object()["to"+String["name"]]["call"]())[11]',
V: null,
W: null,
X: null,
Y: null,
Z: null,
2022-06-01 01:45:41 +00:00
' ': '(NaN+[]["flat"])[11]',
'!': null,
'"': '("")["fontcolor"]()[12]',
2022-06-01 01:45:41 +00:00
'#': null,
$: null,
2022-06-01 01:45:41 +00:00
'%': 'Function("return escape")()([]["flat"])[21]',
'&': '("")["fontcolor"](")[13]',
"'": null,
2022-06-01 01:45:41 +00:00
'(': '([]["flat"]+"")[13]',
')': '([0]+false+[]["flat"])[20]',
'*': null,
'+': '(+(+!+[]+(!+[]+[])[!+[]+!+[]+!+[]]+[+!+[]]+[+[]]+[+[]])+[])[2]',
',': '[[]]["concat"]([[]])+""',
'-': '(+(.+[0000001])+"")[2]',
'.': '(+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]',
'/': '(false+[0])["italics"]()[10]',
':': '(RegExp()+"")[3]',
';': '("")["fontcolor"](NaN+")[21]',
'<': '("")["italics"]()[0]',
'=': '("")["fontcolor"]()[11]',
'>': '("")["italics"]()[2]',
'?': '(RegExp()+"")[2]',
'@': null,
'[': '([]["entries"]()+"")[0]',
'\\': '(RegExp("/")+"")[1]',
']': '([]["entries"]()+"")[22]',
'^': null,
_: null,
2022-06-01 01:45:41 +00:00
'`': null,
'{': '(true+[]["flat"])[20]',
'|': null,
'}': '([]["flat"]+"")["slice"]("-1")',
'~': null,
};
const GLOBAL = 'Function("return this")()';
function fillMissingDigits() {
var output, number, i;
for (number = 0; number < 10; number++) {
2022-06-01 01:45:41 +00:00
output = '+[]';
if (number > 0) {
2022-06-01 01:45:41 +00:00
output = '+!' + output;
}
for (i = 1; i < number; i++) {
2022-06-01 01:45:41 +00:00
output = '+!+[]' + output;
}
if (number > 1) {
output = output.substr(1);
}
2022-06-01 01:45:41 +00:00
MAPPING[number] = '[' + output + ']';
}
}
function replaceMap() {
2022-06-01 01:45:41 +00:00
var character = '',
value,
i,
key;
function replace(pattern, replacement) {
2022-06-01 01:45:41 +00:00
value = value.replace(new RegExp(pattern, 'gi'), replacement);
}
function digitReplacer(_, x) {
return MAPPING[x];
}
function numberReplacer(_, y) {
2022-06-01 01:45:41 +00:00
var values = y.split('');
var head = +values.shift();
2022-06-01 01:45:41 +00:00
var output = '+[]';
if (head > 0) {
2022-06-01 01:45:41 +00:00
output = '+!' + output;
}
for (i = 1; i < head; i++) {
2022-06-01 01:45:41 +00:00
output = '+!+[]' + output;
}
if (head > 1) {
output = output.substr(1);
}
return [output]
.concat(values)
2022-06-01 01:45:41 +00:00
.join('+')
.replace(/(\d)/g, digitReplacer);
}
for (i = MIN; i <= MAX; i++) {
character = String.fromCharCode(i);
value = MAPPING[character];
if (!value) {
continue;
}
for (key in CONSTRUCTORS) {
2022-06-01 01:45:41 +00:00
replace('\\b' + key, CONSTRUCTORS[key] + '["constructor"]');
}
for (key in SIMPLE) {
replace(key, SIMPLE[key]);
}
2022-06-01 01:45:41 +00:00
replace('(\\d\\d+)', numberReplacer);
replace('\\((\\d)\\)', digitReplacer);
replace('\\[(\\d)\\]', digitReplacer);
2022-06-01 01:45:41 +00:00
replace('GLOBAL', GLOBAL);
replace('\\+""', '+[]');
replace('""', '[]+[]');
MAPPING[character] = value;
}
}
function replaceStrings() {
var regEx = /[^\[\]\(\)\!\+]{1}/g,
all,
value,
missing,
count = MAX - MIN;
function findMissing() {
var all,
value,
done = false;
missing = {};
for (all in MAPPING) {
value = MAPPING[all];
if (value && value.match(regEx)) {
missing[all] = value;
done = true;
}
}
return done;
}
function mappingReplacer(a, b) {
2022-06-01 01:45:41 +00:00
return b.split('').join('+');
}
function valueReplacer(c) {
return missing[c] ? c : MAPPING[c];
}
for (all in MAPPING) {
if (MAPPING[all]) {
MAPPING[all] = MAPPING[all].replace(
/\"([^\"]+)\"/gi,
mappingReplacer
);
}
}
while (findMissing()) {
for (all in missing) {
value = MAPPING[all];
value = value.replace(regEx, valueReplacer);
MAPPING[all] = value;
missing[all] = value;
}
if (count-- === 0) {
2022-06-01 01:45:41 +00:00
console.error('Could not compile the following chars:', missing);
}
}
}
function escapeSequence(c) {
var cc = c.charCodeAt(0);
if (cc < 256) {
2022-06-01 01:45:41 +00:00
return '\\' + cc.toString(8);
} else {
var cc16 = cc.toString(16);
2022-06-01 01:45:41 +00:00
return '\\u' + ('0000' + cc16).substring(cc16.length);
}
}
function escapeSequenceForReplace(c) {
2022-06-01 01:45:41 +00:00
return escapeSequence(c).replace('\\', 't');
}
function encode(input, wrapWithEval, runInParentScope) {
var output = [];
if (!input) {
2022-06-01 01:45:41 +00:00
return '';
}
2022-06-01 01:45:41 +00:00
var unmappped = '';
for (var k in MAPPING) {
if (MAPPING[k]) {
unmappped += k;
}
}
2022-06-01 01:45:41 +00:00
unmappped = unmappped.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
unmappped = new RegExp('[^' + unmappped + ']', 'g');
var unmappedCharactersCount = (input.match(unmappped) || []).length;
if (unmappedCharactersCount > 1) {
// Without this optimization one unmapped caracter has encoded length
// of about 3600 characters. Every additional unmapped character adds
// 2000 to the total length. For example, the lenght of `~` is 3605,
// `~~` is 5600, and `~~~` is 7595.
//
// The loader with replace has encoded length of about 5300 characters
// and every additional character adds 100 to the total length.
// In the same example the length of `~~` becomes 5371 and `~~~` -- 5463.
//
// So, when we have more than one unmapped character we want to encode whole input
// except select characters (that have encoded length less than about 70)
// into an escape sequence.
//
// NOTE: `t` should be escaped!
input = input.replace(
/[^0123456789.adefilnrsuN]/g,
escapeSequenceForReplace
);
} else if (unmappedCharactersCount > 0) {
//Because we will wrap the input into a string we need to escape Backslash
// and Double quote characters (we do not need to worry about other characters
// because they are not mapped explicitly).
// The JSFuck-encoded representation of `\` is 2121 symbols,
// so esacped `\` is 4243 symbols and escaped `"` is 2261 symbols
// however the escape sequence of that characters are
// 2168 and 2155 symbols respectively, so it's more practical to
// rewrite them as escape sequences.
input = input.replace(/["\\]/g, escapeSequence);
//Convert all unmapped characters to escape sequence
input = input.replace(unmappped, escapeSequence);
}
2022-06-01 01:45:41 +00:00
var r = '';
for (var i in SIMPLE) {
2022-06-01 01:45:41 +00:00
r += i + '|';
}
2022-06-01 01:45:41 +00:00
r += '.';
2022-06-01 01:45:41 +00:00
input.replace(new RegExp(r, 'g'), function (c) {
var replacement = SIMPLE[c];
if (replacement) {
2022-06-01 01:45:41 +00:00
output.push('(' + replacement + '+[])');
} else {
replacement = MAPPING[c];
if (replacement) {
output.push(replacement);
} else {
2022-06-01 01:45:41 +00:00
throw new Error('Found unmapped character: ' + c);
}
}
});
2022-06-01 01:45:41 +00:00
output = output.join('+');
if (/^\d$/.test(input)) {
2022-06-01 01:45:41 +00:00
output += '+[]';
}
if (unmappedCharactersCount > 1) {
// replace `t` with `\\`
output =
2022-06-01 01:45:41 +00:00
'(' +
output +
2022-06-01 01:45:41 +00:00
')[' +
encode('split') +
'](' +
encode('t') +
')[' +
encode('join') +
'](' +
encode('\\') +
')';
}
if (unmappedCharactersCount > 0) {
output =
2022-06-01 01:45:41 +00:00
'[][' +
encode('flat') +
']' +
'[' +
encode('constructor') +
']' +
'(' +
encode('return"') +
2022-06-01 01:45:41 +00:00
'+' +
output +
2022-06-01 01:45:41 +00:00
'+' +
encode('"') +
2022-06-01 01:45:41 +00:00
')()';
}
if (wrapWithEval) {
if (runInParentScope) {
output =
2022-06-01 01:45:41 +00:00
'[][' +
encode('flat') +
']' +
'[' +
encode('constructor') +
']' +
'(' +
encode('return eval') +
')()' +
'(' +
output +
2022-06-01 01:45:41 +00:00
')';
} else {
output =
2022-06-01 01:45:41 +00:00
'[][' +
encode('flat') +
']' +
'[' +
encode('constructor') +
']' +
'(' +
output +
2022-06-01 01:45:41 +00:00
')()';
}
}
return output;
}
fillMissingDigits();
replaceMap();
replaceStrings();
/* ============================================= */
print(encode(readline()));