Pat*_*rio 3 php passwords generator brute-force
我希望能够输入一个数字并获得一个密码,由字符串或唯一字符构成.所以如果我在字符串中有两个字符:$ string ="AB"; 这些都是理想的结果:
-in-|-out-
0 | A
1 | B
2 | AA
3 | AB
4 | BA
5 | BB
6 | AAA
7 | AAB
8 | ABA
9 | ABB
10 | BBB
Run Code Online (Sandbox Code Playgroud)
等等.这是我目前的代码:
for($i = 1; $i < 100; $i++)
{
echo createString ($i, "AB")."<br/>";
}
function createString ($id, $chars) // THE ISSUE <---
{
$length = getLength($id, $chars);
//echo "LENGTH : ".$length."<br/><br/>";
$string = "";
for($i = 0; $i < $length; $i++)
{
$a = round(($id - 1)/pow($length, $i)); // THE ISSUE <-----
$local = local($a, strlen($chars));
$string = $chars{$local - 1}." : ".$string;
}
return $string;
}
function local ($num, $max)
{
$num += $max;
while($num > $max)
{
$num -= $max;
}
return $num;
}
/*
get the length of the output by inputing the "in" and defining the possible characters
*/
function getLength ($id, $chars)
{
$charNUM = 1;
$LR = -1;
$HR = 0;
while(true)
{
$LR = $HR;
$HR = pow(strlen($chars), $charNUM) + $LR;
$LR += 1;
//echo $LR." : ".$HR." : ".$charNUM."<br/>";
if($id >= $LR && $id <= $HR)
{
return $charNUM;
}
if($id < $LR)
{
return false;
}
$charNUM ++;
}
}
Run Code Online (Sandbox Code Playgroud)
那输出:
B :
A :
A : B :
B : A :
B : B :
A : A :
A : B : B :
A : B : A :
A : A : B :
A : A : A :
A : A : B :
A : B : A :
A : B : B :
A : B : A :
B : A : B : B :
B : A : B : A :
B : A : B : B :
B : A : B : A :
B : A : A : B :
B : A : A : A :
B : A : A : B :
B : A : A : A :
B : A : B : B :
B : A : B : A :
B : B : B : B :
B : B : B : A :
B : B : A : B :
B : B : A : A :
B : B : A : B :
B : B : A : A :
B : B : A : B : B :
B : B : A : B : A :
B : B : A : B : B :
B : B : A : A : A :
B : B : A : A : B :
B : B : A : A : A :
B : B : A : A : B :
B : B : A : A : A :
B : B : B : B : B :
B : B : B : B : A :
B : B : B : B : B :
Run Code Online (Sandbox Code Playgroud)
等等.但它重复了一遍.我遇到了函数createString()的问题.我想在没有预先计算的情况下在暴力密码表的某处访问密码.我不想要一个预先计算好的数组,只需访问它的一个点.
我将在此处发布用于将任何正整数转换为任何给定正整数基数 (>1) 的系统的代码,该系统返回每个数字的值。
function convert($number, $base)
{
$return = array();
do{
$return[] = $number % $base;
$number = floor($number / $base);
}while($number != 0);
return $return;
}
Run Code Online (Sandbox Code Playgroud)
所以你会调用 use 这个函数,如下所示:
function createString($i, $base)
{
$res = convert($i, strlen($base));
$str = "";
foreach($res as $digit)
{
$str = $base[$digit] . $str;
}
return $str;
}
Run Code Online (Sandbox Code Playgroud)
试试看。它的格式与您的输出略有不同,但应该是可读的。
基本“AB”的一些示例输出:
0 -> A
1 -> B
2 -> BA
3 -> BB
4 -> BAA
5 -> BAB
6 -> BBA
7 -> BBB
8 -> BAAA
9 -> BAAB
10-> BABA
11-> BABB
12-> BBAA
13-> BBAB
14-> BBBA
15-> BBBB
Run Code Online (Sandbox Code Playgroud)