title: How does this code generate the proper sequence of characters?
body: <p>The code in question comes from <a href="http://www.codegravity.com/projects/mathguard" rel="nofollow">MathGuard</a>, a PHP anti-spam CAPTCHA script that requires the user to answer a simple math problem. It displays the digits and operator symbols as 3x5 matrices of random characters. I understand how the code works in the sense that I can follow the code and understand what it's doing; I just don't understand how one would come to this solution.</p>
  
  <p>This function takes an integer that describes one line of the 3x5 matrix and converts it into a line of random characters:</p>
  
  <pre><code>function decToBin($dec) {
      $pattern = "123456789ABCDEFGHIJKLMNOPQRTSTUWXYZ";
      $output = "   ";
      $i = 0;
      do {
          if ($dec % 2) {
              $rand = rand() % 34;
              $output { 2 - $i } = $pattern { $rand };
          } else {
              $output { 2 - $i } = " ";
          }
          $dec = (int) ($dec / 2);
          $i++;
      } while ($dec &gt; 0);
      $output = str_replace(" ", "&amp;nbsp;", $output);
      return $output;
  }
  </code></pre>
  
  <p>Here are the digit descriptors:</p>
  
  <pre><code>$number = array (
      array ( 7, 5, 5, 5, 7 ), // 0
      array ( 2, 6, 2, 2, 7 ), // 1
      array ( 7, 1, 7, 4, 7 ), // 2
      array ( 7, 1, 7, 1, 7 ), // 3
      array ( 4, 5, 7, 1, 1 ), // 4
      array ( 7, 4, 7, 1, 7 ), // 5
      array ( 7, 4, 7, 5, 7 ), // 6
      array ( 7, 1, 1, 1, 1 ), // 7
      array ( 7, 5, 7, 5, 7 ), // 8
      array ( 7, 5, 7, 1, 7 )  // 9
  );
  </code></pre>
  
  <p>My question is: <strong>how does one come to this conclusion and method of generation and know that, for example, <code>7</code> will generate a full line of random characters, and <code>5</code> only the outermost characters?</strong></p>
  
  <p>Is this just a form of code obfuscation? What makes this method better than, say, storing the digits as a string (<code>111101101101111</code> as <code>0</code>, for example) and replacing each <code>1</code> with a random character?</p>