/** * @test */ public function itShouldGetValidModulus() { $this->assertEquals(my_bcmod("7044060001970316212900", 150), "50"); }
function dec2string($decimal, $base) { global $charset; // convert a decimal number into a string using $base $string = null; $base = (int) $base; $charset_size = strlen($charset); // echo 'BASE must be in the range 2-9 or 11-62'; if ($base < 2 | $base > $charset_size) { return false; } if ($base == 10) { return $decimal; } // strip off excess characters (anything beyond $base) $charset_local = substr($charset, 0, $base); // $error['dec_input'] = 'Value must be a positive integer with < 80 digits we are using bcmod!'; if (!is_numeric(trim($decimal))) { return false; } // || strlen(trim($decimal))>80) return false; do { // get remainder after dividing by BASE $remainder = my_bcmod($decimal, $base); $char = substr($charset_local, $remainder, 1); // get CHAR from array $string = "{$char}{$string}"; $decimal = bcdiv(bcsub($decimal, $remainder), $base); } while ($decimal > 0); return $string; }
function bcmod($x, $y) { return my_bcmod($x, $y); }