Forum Moderators: coopster

Message Too Old, No Replies

MD5/SHA1 Decrypter.

Is getting an error.

         

L33t_J0rdan

6:58 am on Jun 23, 2010 (gmt 0)

10+ Year Member




Parse error: syntax error, unexpected T_STRING in C:\xampp\xampplite\htdocs\decrypt.php on line 3


Is the error I'm getting. Here's my code:


<?php

if($_GET['main'] == "decypter") {

$characters = array('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','!','?','1','2','3','4','5','6','7','8','9','0',';',':','!','"','£', '$','%','^,'&','*','+','?','.','|','¬');
$i++;

foreach($characters=>$i) {
if($_POST['md5']) {
if(md5($characters) == $_POST['encypted']) {
echo 'Decrypted! Your decrypted string is: \''.$characters.'\'. :) Have fun!';
exit;
} else if(md5($characters) != $_POST['encypted']) {
echo 'Failed attempt';
return;
}
}

} else if($_POST['sha1']) {
if(sha1($characters) == $_POST['encypted']) {
echo 'Decrypted! Your decrypted string is: \''.$characters.'\'. :) Have fun!';
exit;
} else if(md5($characters) != $_POST['encypted']) {
echo 'Failed attempt';
return;
}
}

}
}
?>

<html>
<head>
<title> decypter! </title>
</head>
<body>
<form action="?main=decrypter" method="POST">
<textbox name="encypted"></textbox>
<input type="radio" name="radio1" value="SHA1" checked> SHA1<br/>
<input type="radio" name="radio1" value="MD5"> MD5<br/>

<input type="submit" value="Login"></div>
</form>
</body>
</head>


And I think I'm sure about: it'll only test singular characters instead of multiple, can you help me on that as well please?

[edited by: eelixduppy at 10:00 am (utc) on Jun 23, 2010]
[edit reason] fixed side scroll [/edit]

Matthew1980

7:26 am on Jun 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there l33t_jordan,

Your form isn't going to the right action reference:

<form action="?main=decrypter" method="POST">

php file:-

if(isset($_GET['main']) && ($_GET['main'] == "decypter")){
//process data
}else{
//redirect to form, error posting
}

Check to see if it is set, you need the error handler there

If the names don't match, I won't work ;)

and these need to be lowercase too:

<input type="radio" name="radio1" value="SHA1" checked> SHA1<br/>
<input type="radio" name="radio1" value="MD5"> MD5<br/>

Just to note part of that array can be replaced with:-

range('A','Z');

I have only had a quick read, but that's what sticks out the most to me ;)

Cheers,
MRb

enigma1

1:53 pm on Jun 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



check the single quotes and comas you are missing one,

,'^,

should been
,'^',

L33t_J0rdan

3:24 pm on Jun 23, 2010 (gmt 0)

10+ Year Member



I've now got:

<?php

if($_GET['main'] == "decrypter") {

$characters = array(range('A','Z'),'!','?',range('0','9'),';',':','!','"','£','$','%','^','&','*','+','?','.','|','¬');
$i++;

foreach($characters=>$i) {
if($_POST['md5']) {
if(md5($characters) == $_POST['encypted']) {
echo 'Decrypted! Your decrypted string is: \''.$characters.'\'. :) Have fun!';
exit;
} else if(md5($characters) != $_POST['encypted']) {
echo 'Failed attempt';
return;
}
}

} else if($_POST['sha1']) {
if(sha1($characters) == $_POST['encypted']) {
echo 'Decrypted! Your decrypted string is: \''.$characters.'\'. :) Have fun!';
exit;
} else if(md5($characters) != $_POST['encypted']) {
echo 'Failed attempt';
return;
}
}

}
}
?>

<html>
<head>
<title> decypter! </title>
</head>
<body>
<form action="?main=decrypter" method="POST">
<textbox name="encypted"></textbox>
<input type="radio" name="radio1" value="sha1" checked> SHA1<br/>
<input type="radio" name="radio1" value="md5"> MD5<br/>

<input type="submit" value="Login"></div>
</form>
</body>
</head>


and I'm now getting the error:
Parse error: syntax error, unexpected T_DOUBLE_ARROW in C:\xampp\xampplite\htdocs\decrypt.php on line 8

Matthew1980

3:40 pm on Jun 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there l33t_jordan,

Incorrect syntax:-

foreach(ARRAY TO EVALUATE AS $characters=>$i){
//loop stuff here
}

You need to specify something, foe example if it were a $_POST:-

foreach($_POST AS $key=>$value){
//loop stuff here
}

[EDIT:]
Also, I'm not too sure why you are returning at the end of the string, there is nothing to return, stick with the exit; as you have done on the previous case, only use return if you need to send something back from a function as it is the returned value from a function


You get the idea,

Cheers,
MRb

TheMadScientist

6:09 pm on Jun 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Uh, you're missing the ' and lowercase a to z (possibly more) which means you're going to have an additional 27 characters (at least) with your current 53... Are you seriously going to try to brute force an 80 possible character password combination that's usually 6 or more characters on your server? That's 80^6 combinations minimum if my math is anywhere near correct... If it's 10 characters your looking at 80^10?!

Yeah, I mean 80*80*80*80*80*80 or 2.62144 x 10^11 or 262,144,000,000 (262 billion) minimum combinations. There are 84,600 seconds per day so at 3,098,628 attempts per second you'll exhaust 6 character password combinations in 24 hours. Of course if you can only get 30,986 per second your minimum run time to exhaust 6 character possibilities will be 100 x longer.

I hope you have your max script run time set high, patient visitors, and some huge processing power if this is something you actually plan to try and run on a server. There's a reason people don't do it...

L33t_J0rdan

6:31 am on Jun 24, 2010 (gmt 0)

10+ Year Member



Wouldn't exit; stop the script though? I want it to continue.

Matthew1980

7:08 am on Jun 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there l33t_jordan,

Well then in that case, you can leave out the return; instructions, because you have to ask yourself when using that, "what am I returning from this, does it need it".

If you need something returned as I said before, it will either be from an if/elseif/else chain, switch statement or a plain function where you need to have a single var (constructed string) or array (multiple strings or data) returned as value from parameters that have been passed into it for processing.

Unless I missed a day in class those are the only situations whereby a return could/should be used.

Hope that makes sense to you.

Cheers,
MEb