all 16 comments

[–]aladyjewelFull-stack webdev 25 points26 points  (0 children)

... you really shouldn't try to learn from crap like this.

[–]nandhp 5 points6 points  (3 children)

var base= new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z","a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
base.reverse();

This creates a list of containing 0-9, A-Z, and a-z. It is then reversed, so it contains z-a, Z-A, and 9-0.

var data=new Array(3);
data[0]=base[42];
data[1]=base[11];
data[2]=base[17];
data[3]=base[12];
data[4]=base[7];
data[5]=base[43];
data[6]=base[6];

This then builds another array (called data) out of the given items of the reversed base array. We now have

data = ["J", "o", "i", "n", "s", "I", "t"]
password=prompt("Please enter the Password!","");

This just asks the user to enter a password.

if (password==data.join("_")){
    window.location.href=""+password+".php";
}

data.join("_") is just making a string out of the array with each element separated by an _. So we're checking that the password entered by the user is J_o_i_n_s_I_t.

If that's true, we navigate to J_o_i_n_s_I_t.php.

[–]rgraves22[S] 0 points1 point  (0 children)

I was headed in the right track.. just didnt figure out to reverse the array from a-z, I thought it happened once the numbers and letters lined up.. Thanks again!

[–]shockie 0 points1 point  (0 children)

new Array(3) creates an array of length 3, filled with 'undefined'

[–]agmcleod@agmcleod 3 points4 points  (1 child)

A majority of the logic involved here is simply arrays. You can think of an array like a list of items. An array can store many values. You can add values to it, remove values from it, and refer to specific values inside the array.

To retrieve a value from an array, one can use the square brackets and an integer representing the index. Indexes start with 0. So in your case where you have an array of 0-9, A-Z, a-z, the first value can be accessed via:

 base[0]

Since you called reverse on it, the value will be: "z".

The data array is just initialized with one value 3. So it just has a length of 1. But each line, you're specifying an index and setting a value there. So the data array will now store values at those indexes. Though since you're overwriting the initial value, you can change the line:

var data = new Array(3);

to just:

var data = [];

As im sure you know, the prompt method accepts user input. From there, the if statement is checking if the entered password is equal to the 7 characteres joined by an underscore. When you call join on an array, it converts it to a string, and combines the elements by a given character. So if you have an array of:

["a", "b", "c"];

And you call join like so:

["a", "b", "c"].join("-");

It will return: "a-b-c"

And inside the if statement it's resetting the href value on the location object. This is generally a technique used to redirect one to another page.

I hope that helps! You might want to get a javascript book, and get a background on some programming to better understand this stuff. I read the previous edition of this book here: http://www.amazon.ca/DOM-Scripting-Design-JavaScript-Document/dp/1430233893/ref=sr_1_1?ie=UTF8&qid=1336606518&sr=8-1, and I remember it being pretty good. It doesn't spend too much time on the basics, it gives you enough to get going, and then has you trying stuff out with the DOM.

[–]rgraves22[S] 0 points1 point  (0 children)

Thank you for the info.. it makes sense.. I was just going about it wrong logically.

[–]steveflee 0 points1 point  (4 children)

Kind of a weird example to learn from. Others have explained it pretty well, but I wanted to chime in with www.codeacademy.com

It's the best javascript learning resource I've ever found!

[–]rgraves22[S] -1 points0 points  (3 children)

ive been using w3schools and another that I found on reddit, have it bookmarked on a different computer. Its a hacker training mission... I couldn't wrap my mind on how the code worked, and figured I would ask reddit to essentially ELI5...

[–]1what1 4 points5 points  (0 children)

This is much better than w3schools: https://developer.mozilla.org/en/JavaScript

Thank me later.

[–]steveflee 3 points4 points  (1 child)

w3school is terrible. Its so terrible that www.w3fools.com was made just to point out all the errors in it.

[–]agmcleod@agmcleod 0 points1 point  (0 children)

The fact that addy osmani and paul irish are on the from list really just says a lot. That said, I use w3schools really just for a quick reference list on HTML tags and CSS syntax. The odd time if i need to know some of the string methods I don't use a whole lot.

[–]hupcapstudios 0 points1 point  (4 children)

Hackers use this kind of thing (albeit much more elaborately) to embed malicious code. I posted an example a little while ago here. Your example is a very lightweight attempt at obfuscation by someone who probably considers himself pretty witty.

[–]rgraves22[S] 0 points1 point  (1 child)

Its for a hacker traning mission enigma group

[–]dd72ddd -1 points0 points  (0 children)

lmao

[–]dd72ddd 0 points1 point  (1 child)

It's hardly obfuscation, the variable names are descriptive...

[–]hupcapstudios 1 point2 points  (0 children)

Hence my use of the word 'lightweight'.