js-magic
**  
crypto  
cyberedu

Javascript Obfuscation 101.
The file received contains javascript obfuscated code.

I first ran it in the obfuscated state: I made a simple html page and put it as a script for that page.




It returned an array which looked like the flag



I then checked what the obfuscated code actually does.
I used this website: https://lelinhtinh.github.io/de4js/ to deobfuscate it.

The important part from the deobfuscated code:
function reverse_string(param) {
var _15 = param.split('');
var _16 = _15.reverse();
var _13 = _16.join('');
return _13
}

function chunkString(_17, _18) {
return _17.match(new RegExp('.{1,' + _18 + '}', 'g'))
}

function enc1(param) {
// adds 0x14 to each character
nchunk = [];
for (var i = 0x0; i < param.length; i++) {
nchunk.push(String.fromCharCode(param[i].charCodeAt() + 0x14))
}
return nchunk.join('')
}


function enc2(_9) {
// substracts 0x14 from each character
nchunk = [];
for (var _5 = 0x0; _5 < _9.length; _5++) {
nchunk.push(String.fromCharCode(_9[_5].charCodeAt() - 0x14))
}
return nchunk.join('')
}

function enc3(_19) {
// reverses the string
nchunk = reverse_string(_19);
return nchunk
}

function encode(flag) {
// alternates between the encryption functions until it fully encrypts the flag
functs = [enc1, enc2, enc3];
for (var i = 0x0; i < flag.length; i++) {
flag[i] = functs[i % 3](flag[i])
console.log(functs[i % 3](flag[i]))
}
return flag
}

The functions I wrote to decrypt the flag:
var flag=
[
"mk{",
"\u001bS=",
"3b0",
"‹\\\\",
"\n\u0011\u0010",
"fc1",
"‹Y\\",
"\u00119>",
"bf4",
"‹`a",
"\u0011\u000e>",
"b92",
"\\Z_",
"9=\f",
"1e4",
"^\\a",
":\u0011\u000b",
"4ca",
"\\a]",
"\u0011\u0011\t",
"b78",
"]ZŠ",
"\u0010\r\r",
"}"
]

function dec1(param) {
nchunk = [];
for (var i = 0x0; i < param.length; i++) {
nchunk.push(String.fromCharCode(param[i].charCodeAt() - 0x14))
}
return nchunk.join('')
}


function dec2(_9) {
nchunk = [];
for (var _5 = 0x0; _5 < _9.length; _5++) {
nchunk.push(String.fromCharCode(_9[_5].charCodeAt() + 0x14))
}
return nchunk.join('')
}

function dec3(_19) {
nchunk = reverse_string(_19);
return nchunk
}

function decode(flag) {
functs = [dec1, dec2, dec3];
for (var i = 0x0; i < flag.length; i++) {
flag[i] = functs[i % 3](flag[i])
console.log(functs[i % 3](flag[i]))
}
}


The output:
ECSC{e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855}