Beispiel #1
0
 public function select()
 {
     $this->fields = array();
     if (func_num_args() == 1) {
         $str = str_replace(",", "", func_get_arg(0));
         $str = str_replace(";", " ", $str);
         $arr = explode(" ", $str);
         foreach ($arr as $key => $value) {
             if (trim($value) != "") {
                 array_push($this->fields, $this->parseSelectItem($value));
             }
         }
     } else {
         for ($i = 0; $i < func_num_args(); $i++) {
             $value = func_get_arg($i);
             if (trim($value) != "") {
                 array_pus($this->fields, $this->parseSelectItem($value));
             }
         }
     }
     return $this;
 }
 function pow_mod($p, $q, $r)
 {
     // Extract powers of 2 from $q
     $factors = array();
     $div = $q;
     $power_of_two = 0;
     while (bccomp($div, "0") == BCCOMP_LARGER) {
         $rem = bcmod($div, 2);
         $div = bcdiv($div, 2);
         if ($rem) {
             array_push($factors, $power_of_two);
         }
         $power_of_two++;
     }
     // Calculate partial results for each factor, using each partial result as a
     // starting point for the next. This depends of the factors of two being
     // generated in increasing order.
     $partial_results = array();
     $part_res = $p;
     $idx = 0;
     foreach ($factors as $factor) {
         while ($idx < $factor) {
             $part_res = bcpow($part_res, "2");
             $part_res = bcmod($part_res, $r);
             $idx++;
         }
         array_pus($partial_results, $part_res);
     }
     // Calculate final result
     $result = "1";
     foreach ($partial_results as $part_res) {
         $result = bcmul($result, $part_res);
         $result = bcmod($result, $r);
     }
     return $result;
 }