SDL2 example
[mirrors/Programs.git] / php / skripty / rada_crack3.php
1 <?php
2 //Settings
3 $start = 0;
4 $stop = 1000;
5 $places = strlen($stop);
6 $tryes = 50; //Tryes to find better
7 $base = 10;
8 //Init
9 error_reporting(0);
10 srand(time());
11
12 /////////////////////////////////////////////////////////////////
13 //
14 function rada_add($name, $istr) { //Funkce pro pridani do rady -> !!! OPTIMALIZOVAT !!! <-
15 if(!eregi($istr, $GLOBALS[$name])) {
16 if( $istr[0] == $GLOBALS[$name][strlen($GLOBALS[$name])-1] ) {
17 $istr = substr($istr, 1);
18 $GLOBALS[$name] = $GLOBALS[$name].$istr;
19 } elseif( $GLOBALS[$name][0] == $istr[strlen($istr)-1] ) {
20 $GLOBALS[$name] = substr($GLOBALS[$name], 1);
21 $GLOBALS[$name] = $istr.$GLOBALS[$name];
22 } else {
23
24 //Nahodne na zacetek nebo konec
25 if(rand(0,1)) {
26 $GLOBALS[$name] = $istr.$GLOBALS[$name];
27 } else {
28 $GLOBALS[$name] = $GLOBALS[$name].$istr;
29 }
30
31 }
32 }
33 //$GLOBALS[$name]=$GLOBALS[$name].$istr; //Debug
34 }
35
36 //
37 function rada_unique($name) { //Funkce pro vyhledani a smazani duplikatu (i potrebnych)
38 $length = $GLOBALS["places"];
39 $replacer = "%";
40
41 for($i=0;$i<(strlen($GLOBALS[$name])-$length);$i++) {
42
43 $sub = substr($GLOBALS[$name], $i, $length);
44 for($x=0;$x<$length;$x++) {
45 $GLOBALS[$name][($i+$x)] = $replacer;
46 }
47
48 $GLOBALS[$name] = str_replace($sub, "", $GLOBALS[$name]); //Smaze duplikaty
49
50 $replace="";
51 for($x=0;$x<$length;$x++) {
52 $replace = $replace.$replacer;
53 }
54
55 $GLOBALS[$name] = str_replace($replace, $sub, $GLOBALS[$name]);
56 }
57
58 }
59
60 //
61 function add_zeroes($num, $places) { //Zarovna cislo na $places mist pridanim nul na zacatek
62 $str = "";
63 for($i=0;$i<$places;$i++) {
64 $str = $str."0";
65 }
66 //$num = base_convert($num, 10, $base); //BASE CONVERT -> !!! NOT WORKS YET !!! <-
67 $str=$str.$num;
68 $str = substr($str, strlen($str)-$places);
69 return $str;
70 }
71
72 ///CODE///////////////////////////////////////////
73 //Test
74 //die(add_zeroes(23, 5));
75 //////////////////////////////////////////////////
76 $try = $tryes;
77 $next = true;
78 while($next) { //MAIN LOOP
79 $next = false;
80
81 $rada = ""; //Vytvorime prazdnou radu
82 for($i=$start;$i<=$stop;$i++) { //Pridame vsechna n-cisli
83 $istr = add_zeroes($i, $places);
84 rada_add("rada", $istr);
85 }
86
87 rada_unique("rada");
88
89 $notfound = 0;
90 for($i=$start;$i<=$stop;$i++) {
91 $istr = add_zeroes($i, $places);
92 if(!eregi($istr, $rada)) {
93 $notfound++;
94 //echo("Not found: $i\n");
95 $next = true;
96 }
97 }
98
99 echo("Total not found: $notfound\n"); //Debug
100
101 if($try > 0) {
102 if($notfound <= $minnotfound || !isset($minnotfound)) {
103 echo("-minnf: $notfound\n"); //Debug
104 $minnotfound = $notfound;
105 $try = $tryes;
106 } else {
107 $try--;
108 }
109 } else {
110 if($notfound <= $minnotfound || $notfound == 0) $next = false;
111 }
112
113 } //MAIN LOOP
114
115 for($i=$start;$i<=$stop;$i++) { //Pridame vsechna zbyla n-cisli
116 $istr = add_zeroes($i, $places);
117 rada_add("rada", $istr);
118 }
119
120 /////////OUTPUT///////////////////////////////////
121 echo("\n");
122 echo("Length: ".strlen($rada)." chars\n");
123 echo("Total not found: $notfound\n");
124 echo($rada);
125 echo("\n\n");
This page took 0.331064 seconds and 4 git commands to generate.