MatanyaP
MatanyaP

Reputation: 476

Trying to understand this function in javascript from a website sourcecode

OK so I'm doing this wargame challenge and I'm pretty much clueless about HTML and JS. I found this function in the source code stating

"your flag is:"

and then a bunch of gibberish. I assume this function is supposed to make sense in this long string, but I can't understand how it's supposed to do it or how to execute this function independently (if even needed). I do know it's not supposed to be really hard.

this is the function:

function r(){for(var r=0,e=0,a="",l=0;l<n.length;l++)if(n[l].toLowerCase()!=n[l]&&(r+=1),8==++e){if(!t)return;a+=String.fromCharCode(r),r=0,e=0}else r<<=1;return a}var e=!1,t=!1,a=setInterval(function(){e&&(t=!0,alert("Your flag is: "+r()),clearInterval(a));t=!1},1e3),n="xVJvyNQdcLEqIUwenRNdnawBhSNqcVABvERRGlQOiVKlnlwJdINtSRfrxZJnYDsntIzKBOFQzMTBXioIbKGkDJZYoTFWqCzSbWIKsvPxlHaPHEVRiTIiltXqtKEjwzkDkGHEbnMPnFNrnWyLcOlBOVSWtOZxmjdIhRFXugEotQRmyHwZpGnKSDSRaZCrniYgcQVkiFaIgFScWAevgWDkQZALgSWwQDFkkDWlaYOKkDcRGUNSxJlLlRnnfROzNFGSrNcEECFDxZEVeAeVwSEQvxMOxBRGLKlS";

and this is the whole web page:

please help me help myself :)

Upvotes: 0

Views: 115

Answers (2)

Brian Peacock
Brian Peacock

Reputation: 1849

When expanded the minified function looks like this...

function r() {
    for (var r = 0, e = 0, a = '', l = 0; l < n.length; l++) if (n[l].toLowerCase() != n[l] && (r += 1), 8 == ++e) {
        if (!t) return;
        a += String.fromCharCode(r),
        r = 0,
        e = 0
    } else r <<= 1;
    return a
}
var e = !1,
t = !1,
a = setInterval(function () {
    e && (t = !0, alert('Your flag is: ' + r()), clearInterval(a));
    t = !1
}, 1000),
n = 'xVJvyNQdcLEqIUwen...etc...';

Although minified code loads faster this nonetheless goes to show the utility of giving one's variables and functions useful, descriptive names when developing our own applications.

Upvotes: -1

Albi
Albi

Reputation: 1855

The js code you are looking into is minified/compressed code That means the actual code is converted by replacing all the real variable names to (a, b, c,...) making it hard to copy for others and to load it faster on the website.

Upvotes: 2

Related Questions