I
I
Ilyusha Prokopiev2015-11-09 02:07:37
PHP
Ilyusha Prokopiev, 2015-11-09 02:07:37

How to write an algorithm to enumerate all possible combinations of characters?

We need an algorithm in PHP that will send a message to random emails, the email must be selected by brute force, 39 characters are allowed in the email (az, 1-9, dot, underscore, dash) - we are only interested in the part up to the dog. I can not understand in any way how the loop condition should be built. It is clear that the last character will change every 39 characters, the penultimate - every 39 squared, the penultimate - every 39 cubed, but I have no idea what to do with this knowledge.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2015-11-09
@iliapro

well, something like that ... you give a number as input ...

function emailEncode($i)
  {
    $alphabet = "abcdefghijklmnopqrstuvwxyz0123456789._-";
    $alphabet = str_split($alphabet);
    if ($i == 0) 
      return $alphabet[0];
    $result = '';
    $base = count($alphabet);
    while ($i > 0)
    {
      $result[] = $alphabet[($i % $base)];
      $i = floor($i / $base);
    }
    $result = array_reverse($result);
    return join("", $result);
  }

A
Adamos, 2015-11-09
@Adamos

Elementary combinatorics is well analyzed on algolist.ru - there, however, more and more Pascal, but it doesn't matter, because all logic is parsed down to the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question