Moderators Dragos Posted February 19, 2011 Moderators Report Posted February 19, 2011 <?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);?> Quote
cmiN Posted February 19, 2011 Report Posted February 19, 2011 Wtf backtracking iterativ cu limita ? Quote
Xander Posted February 19, 2011 Report Posted February 19, 2011 <?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 Quote
reikoku Posted February 19, 2011 Report Posted February 19, 2011 super tare comentat codu: la "break" //am terminat Quote
Xakepatop Posted February 19, 2011 Report Posted February 19, 2011 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 doritelength = 6function 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. Quote
Xander Posted February 19, 2011 Report Posted February 19, 2011 la prima vedere : if(level<length) trebuie sa fie if($level<$length)si length = 6 trebuie sa fie$length = 6dar recursiv merge mai greu decat iterativ Quote
Xakepatop Posted February 19, 2011 Report Posted February 19, 2011 Ai dreptate Xander, comoditatea de a scrie in python fara $$$$$ ma urmareste oriunde. PS: si tu ai chemat in 2 locuri functii care inca nu au fost declarate dar imi place metoda ta. Quote
cmiN Posted February 19, 2011 Report Posted February 19, 2011 Recursiv sau iterativ se obtine acelasi timp, numai ca recursiv mananca mai multa memorie, iar iterativ sunt mai multe linii de cod si pare mai stufoasa implementarea. Quote
xpt1 Posted February 20, 2011 Report Posted February 20, 2011 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 = 25function 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);?> Quote
l3asketballplayer Posted March 1, 2011 Report Posted March 1, 2011 Nu prea imi place codul tau. Exista in php next_permutation? Quote
em Posted March 1, 2011 Report Posted March 1, 2011 Nu prea imi place codul tau. Exista in php next_permutation?Nope, exista in C++ STL. Quote
hip_hop_x Posted March 15, 2011 Report Posted March 15, 2011 o cerinta, adaugati-l si $start si $stop, ca sa poata fi plasat pe mai multe servere (sa lucreze un fel de multithreaded) Quote
Fahver Posted March 8, 2014 Report Posted March 8, 2014 <?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? Quote
Silviu Posted March 8, 2014 Report Posted March 8, 2014 Este genial, dar ai putea sa-l faci in as fel incat sa genereze si cu caracterele speciale?Adaugi tu in $charset caracterele speciale. Quote
Active Members SynTAX Posted March 8, 2014 Active Members Report Posted March 8, 2014 Este genial, dar ai putea sa-l faci in as fel incat sa genereze si cu caracterele speciale?Probabil nu mai dezgropi threaduri vechi de 3 ani? Quote
Fahver Posted March 9, 2014 Report Posted March 9, 2014 <?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? Quote
Python Posted March 11, 2014 Report Posted March 11, 2014 (edited) Foarte frumos bravo .Dar cu fisierul acesta suprasoliciti serverul. Edited March 11, 2014 by Python Quote