PDA

View Full Version : im having a decoding problem


Digital
09-18-2002, 08:08 PM
i am learning java and i thought it was similar to javascript too. so i took a look at this script, but i couldnt figure it out. Could you tell me what the variable interpret is after its done running the script? thanks alot!



<HTML>
<HEAD>
<TITLE>Null</TITLE>
<SCRIPT>

var texts = "a43b12cde7fd7d6210";
var interpret = "";
var whatisthis = "var xorm = prompt('Enter the password:','');
for (x=1; x<5; x++)
{
interpret += (texts.indexOf(x)+1);
}
interpret += 5;
if (xorm==interpret)
{
interpret = interpret + '.php';location.href=interpret;
}
else{location.href='hahaha.php';}";

eval(whatisthis);

</SCRIPT>
</HEAD>
<BODY>&nbsp;</BODY>
</HTML>

beetle
09-18-2002, 10:19 PM
That one is pretty easy to figure out. indexOf(x) return the zero-based location of x within the string applied to (in this case, tests) Here's how it looks in machine memory
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <-- Indexes
--------------------------------------------
a 4 3 b 1 2 c d e 7 f d 7 d 6 2 1 0 <-- Character at that index

Since the loop takes x from 1 to 4, we get this

tests.indexOf(1)+1 == '5'
tests.indexOf(2)+1 == '6'
tests.indexOf(3)+1 == '3'
tests.indexOf(4)+1 == '2'
Then '5' is added on at the end

since the variable interpret was initialized as a string, these values are added thusly, and not mathematically added, so our answer is '56325' (and not 21 ;))

However, despite this enlightening explanation, you could have easily figured this with 1 simple line of code
<HTML>
<HEAD>
<TITLE>Null</TITLE>
<SCRIPT>

var texts = "a43b12cde7fd7d6210";
var interpret = "";
var whatisthis = "var xorm = prompt('Enter the password:','');
for (x=1; x<5; x++)
{
interpret += (texts.indexOf(x)+1);
}
interpret += 5;
alert(interpret); // <-- See?
if (xorm==interpret)
{
interpret = interpret + '.php';location.href=interpret;
}
else{location.href='hahaha.php';}";

eval(whatisthis);

</SCRIPT>
</HEAD>
<BODY> </BODY>
</HTML>

Digital
09-19-2002, 05:33 PM
thanks alot dude!