Skip to content

Instantly share code, notes, and snippets.

@chinpirako
Created Aug 10, 2022
Embed
What would you like to do?
Gist pour le code qui génère le tout
const encodedMinimumMap = {};
const encodedZero = '+[]';
const encodedOne = '+!![]';
const encodedFalse = '![]';
const encodedTrue = `!![]`;
const encodedNaN = '+[![]]';
const encodedUndefined = '[][+!![]]';
const encodedInfinity = '+!![]/+[]';
const encodeNumber = numberToEncode => {
if (numberToEncode === 0) return encodedZero;
let result = '';
for (let i = 0; i < numberToEncode; i++) {
result += encodedOne;
}
return result;
}
const encodeString = stringToEncode => stringToEncode.split('').map(x => {
if (!(x in encodedMinimumMap)) {
const charCode = x.charCodeAt(0);
return `([]+[])[${encodeString('constructor')}][${encodeString('fromCharCode')}](${encodeNumber(charCode)})`;
}
return encodedMinimumMap[x];
}).join('+');
encodedMinimumMap.a = `(${encodedNaN}+[])[${encodeNumber(1)}]`;
encodedMinimumMap.d = `(${encodedUndefined}+[])[${encodeNumber(2)}]`;
encodedMinimumMap.e = `(${encodedUndefined}+[])[${encodeNumber(3)}]`;
encodedMinimumMap.f = `(${encodedUndefined}+[])[${encodeNumber(4)}]`;
encodedMinimumMap.o = `({}+[])[${encodeNumber(1)}]`;
encodedMinimumMap.b = `({}+[])[${encodeNumber(2)}]`;
encodedMinimumMap.c = `({}+[])[${encodeNumber(5)}]`;
encodedMinimumMap.t = `({}+[])[${encodeNumber(6)}]`;
encodedMinimumMap[' '] = `({}+[])[${encodeNumber(7)}]`;
encodedMinimumMap.s = `(${encodedFalse}+[])[${encodeNumber(3)}]`;
encodedMinimumMap.r = `(${encodedTrue}+[])[${encodeNumber(1)}]`;
encodedMinimumMap.u = `(${encodedTrue}+[])[${encodeNumber(2)}]`;
encodedMinimumMap.i = `(${encodedInfinity}+[])[${encodeNumber(3)}]`;
encodedMinimumMap.n = `(${encodedInfinity}+[])[${encodeNumber(4)}]`;
encodedMinimumMap.S = `([]+([]+[])[${encodeString('constructor')}])[${encodeNumber(9)}]`;
encodedMinimumMap.g = `([]+([]+[])[${encodeString('constructor')}])[${encodeNumber(14)}]`;
encodedMinimumMap.p = `((/[]/)[${encodeString('constructor')}]+[])[${encodeNumber(14)}]`;
encodedMinimumMap.h = `(${encodeNumber(17)})[${encodeString('toString')}](${encodeNumber(18)})`;
encodedMinimumMap.l = `(${encodeNumber(21)})[${encodeString('toString')}](${encodeNumber(22)})`;
encodedMinimumMap.m = `(${encodeNumber(22)})[${encodeString('toString')}](${encodeNumber(23)})`;
encodedMinimumMap[','] = `(((${encodedMinimumMap.a}+${encodedMinimumMap.a})[${encodeString('split')}]([]+[])+[]))[${encodeNumber(1)}]`;
encodedMinimumMap.C = `((()=>{})[${encodeString('constructor')}](${encodeString('return escape')})()(${encodedMinimumMap[',']}))[${encodeNumber(2)}]`;
const compile = codeToEncode => `(()=>{})[${encodeString('constructor')}](${encodeString(codeToEncode)})()`;
// Ici, mettre le code à convertir
const code = compile("let a = 4;console.log(4*2);");
console.log(code);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment