PDA

View Full Version : Dynamic Combinations Script



SyntaXmasteR
10-17-2006, 05:39 PM
I want to throw this script out there to see if any of you can speed it up. I wrote it in PHP. The script is dynamic so that you can control the conditions under which it runs.

What does the script do?
Runs through every possible combination given a set of characters and the length of an unknown string.

Example Run
Set of Characters:
abcdefghijklmnopqrstuvwxyz
Length of string:
* Characters

Test Script - Print Screen (http://boninroad.com/test/combinations.php)
Script runs slow here because it prints to the screen for every combination
Test Script - No Print Screen (http://boninroad.com/test/combinations2.php)
Actual Run Time

I would like to see if any of you can rewrite or modify the script to speed things up. Here is the script:


<?
//THIS WILL LATER BE USED AS AN INPUT VALUE BY USER
$wordlength=*;
//THIS WILL LATER BE USED AS AN INPUT VALUE BY USER
$combinations=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');

$combinations_length=count($combinations);
$pointer=($wordlength-*);

for($i=0;$i<$wordlength;$i++)
{
$custom_array[$i]=0;
}

// Start TIMER
// SCRIPT FOUND HERE: http://www.desilva.biz/php/timer.html
// -----------
$stimer = explode( ' ', microtime() );
$stimer = $stimer[*] + $stimer[0];
////////////////////////////////////////
while($pointer>=0)
{
$pointer=($wordlength-*);
while($custom_array[$pointer]<$combinations_length)
{
$custom_array[$pointer]=(($custom_array[$pointer])+*);
}
$custom_array[$pointer]=0;
$pointer--;
if($custom_array[$pointer]==($combinations_length-*))
{
while($custom_array[$pointer]==($combinations_length-*))
{
$custom_array[$pointer]=0;
$pointer--;
}
}
$custom_array[$pointer]=(($custom_array[$pointer])+*);
}
// End TIMER
// ---------
$etimer = explode( ' ', microtime() );
$etimer = $etimer[*] + $etimer[0];
printf( "It Took: <b>%f</b> seconds.", ($etimer-$stimer) );
// ---------

?>



I did not write the timer for the script. This was added for timing purposes

If you do not understand how the script works try learning Permutations and Combinations (http://mathforum.org/dr.math/faq/faq.comb.perm.html)

SyntaXmasteR
10-18-2006, 05:06 PM
I added an input function to the script:
Test Script - Input Added (http://boninroad.com/test/combinations*.php)

You can enter any "password" using the lowercase set of characters "a-z". It will output the time it takes for the script to find your password, the location of your password, and the number of combinations it ran through to find your password.