Jump to content
Dragos

[PHP] Generarea tuturor parolelor posibile de 6 caractere

Recommended Posts

  • Moderators

<?php
$file = fopen("parole.txt","w");
$charset = "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 0 1 2 3 4 5 6 7 8 9";
$exp = explode (" ", $charset);
$lim = 61;
for ($a=0;$a<=$lim;$a++)
{
for ($b=0;$b<=$lim;$b++)
{
for ($c=0;$c<=$lim;$c++)
{
for ($d=0;$d<=$lim;$d++)
{
for ($e=0;$e<=$lim;$e++)
{
for ($f=0;$f<=$lim;$f++)
{
$string = $exp[$a] . $exp[$b] . $exp[$c] . $exp[$d] . $exp[$e] . $exp[$f] . "\n";
fwrite($file, $string);
}
}
}
}
}
}
fclose($file);
?>

Link to comment
Share on other sites


<?php
$charset = "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 0 1 2 3 4 5 6 7 8 9";
generare(6,$charset);
function generare($marime , $charset)
{
$charset = explode(" " , $charset);
$chlen = count($charset);
$stiva = array();
$count = 0;
for($i=0 ; $i < $marime ; $i++)
$stiva[$i] = 0;
while(true)
{
$stiva[$marime-1] ++;
for($i=$marime-1 ; $i>=0 ; $i--)
{
if($stiva[$i] == $chlen)
{
if($i==0) break; // am terminat
$stiva[$i-1] ++;
$stiva[$i] = 0;
}
}
$count ++;
if($count==1000000)
{
arata($stiva , $charset);
$count = 0;
}
}
}
function arata($stiva , $charset)
{
$msg = "";
foreach($stiva as $key=>$val)
$msg .= $charset[$val];
echo $msg."\n";
}

?>

putin schimbat :) numai ca asta nu le salveaza :) dar merge cu oricate caractere

Link to comment
Share on other sites

Voi incerca sa modific scriptul tau, sa devina mai elegant si flexibil:


<?php
$file = fopen("parole.txt","w");
$charset = "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 0 1 2 3 4 5 6 7 8 9";
$charset_arr = explode (" ", $charset);

# Lungimea parolelor dorite
length = 6

function compose_passwords($password = '', $level = 0)
{
global $charset_arr;
foreach($charset_arr as $key => $char)
{
$this_level_password = $password.$char;
if(level<length)
{
# nu avem nevoie de parolele mai scurte de 6 caractere, mergem mai departe chemind recursiv aceasta functie
compose_passwords($this_level_password, $level++);
}
else
{
fwrite($file, $this_level_password);
}
}
}

compose_passwords();
fclose($file);
?>

Nu am testat codul. Posibil sa fie erori chiar si elementare, demult nu am scris in php. Dar important e sa intelegi abordarea. Sper sa iti fie de folos munca mea.

Link to comment
Share on other sites

Poate merge asa:

<?php
$file = fopen("parole.txt","w");
$charset = "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 0 1 2 3 4 5 6 7 8 9";
$charset_arr = explode (" ", $charset);

# Lungimea parolelor dorite
$lengthmin = 6
$lengthmax = 25

function compose_passwords($password = '', $level = 0)
{
global $charset_arr;
foreach($charset_arr as $key => $char)
{
$this_level_password = $password.$char;
if($level<$lengthmin)
{
# nu avem nevoie de parolele mai scurte de 6 caractere, mergem mai departe chemind recursiv aceasta functie
compose_passwords($this_level_password, $level++);
}
elseif
{
break 3;
}
else
{
fwrite($file, $this_level_password);
}
}
}

compose_passwords();
fclose($file);
?>

Link to comment
Share on other sites


<?php
$file = fopen("parole.txt","w");
$charset = "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 0 1 2 3 4 5 6 7 8 9";
$exp = explode (" ", $charset);
$lim = 61;
for ($a=0;$a<=$lim;$a++)
{
for ($b=0;$b<=$lim;$b++)
{
for ($c=0;$c<=$lim;$c++)
{
for ($d=0;$d<=$lim;$d++)
{
for ($e=0;$e<=$lim;$e++)
{
for ($f=0;$f<=$lim;$f++)
{
$string = $exp[$a] . $exp[$b] . $exp[$c] . $exp[$d] . $exp[$e] . $exp[$f] . "\n";
fwrite($file, $string);
}
}
}
}
}
}
fclose($file);
?>

Este genial, dar ai putea sa-l faci in as fel incat sa genereze si cu caracterele speciale?

Link to comment
Share on other sites


<?php
$file = fopen("parole.txt","w");
$charset = "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 0 1 2 3 4 5 6 7 8 9";
$exp = explode (" ", $charset);
$lim = 61;
for ($a=0;$a<=$lim;$a++)
{
for ($b=0;$b<=$lim;$b++)
{
for ($c=0;$c<=$lim;$c++)
{
for ($d=0;$d<=$lim;$d++)
{
for ($e=0;$e<=$lim;$e++)
{
for ($f=0;$f<=$lim;$f++)
{
$string = $exp[$a] . $exp[$b] . $exp[$c] . $exp[$d] . $exp[$e] . $exp[$f] . "\n";
fwrite($file, $string);
}
}
}
}
}
}
fclose($file);
?>

Exista vreo functie, ceva, in PHP care poate sa-mi estimeze timpul ramas pana la realizarea intregii liste cu parole?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...