public static function getForString($aString)
 {
     if (!isset(self::$cache[$aString])) {
         $len = strlen($aString);
         if ($len == 1) {
             self::$cache[$aString] = array($aString);
         } else {
             $results = array();
             for ($i = 0; $i < $len; $i++) {
                 $first = $aString[$i];
                 $rest = substr($aString, 0, $i) . substr($aString, $i + 1);
                 foreach (Permutations::getForString($rest) as $aPermOfRest) {
                     $results[] = $first . $aPermOfRest;
                 }
             }
             self::$cache[$aString] = $results;
         }
     }
     return self::$cache[$aString];
 }
try {
    $dbh = new PDO($dsn, $user, $pass);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
    die();
}

$sth = $dbh->prepare('INSERT INTO RainbowTable (combination, hash) VALUES (?, ?)');

$total = 0;

// Generating all the combinations of gestures with length three, four, ..., eight and nine 
for ($x = 3; $x <= 9; $x++) {
  echo "==> Generating table for $x ... \n";

  $p = new Permutations(9, $x);
  
  $combinations = 0;
  
  $values = $p->getCurrent();
  
  do {
    $str = "";
    
    foreach ($values as $value) {
      $str .= chr($value);
    }
    
    $hash = sha1($str);
    
    if ($sth->execute( array( implode(",", $values) , $hash) )) {