]> git.mxchange.org Git - friendica.git/blob - library/phpsec/PHP/Compat/Function/bcpowmod.php
bug #96 move libraries to library - better alignment of like rotator
[friendica.git] / library / phpsec / PHP / Compat / Function / bcpowmod.php
1 <?php\r
2 // $Id: bcpowmod.php,v 1.1 2007/07/02 04:19:55 terrafrost Exp $\r
3 \r
4 \r
5 /**\r
6  * Replace bcpowmod()\r
7  *\r
8  * @category    PHP\r
9  * @package     PHP_Compat\r
10  * @license     LGPL - http://www.gnu.org/licenses/lgpl.html\r
11  * @copyright   2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>\r
12  * @link        http://php.net/function.bcpowmod\r
13  * @author      Sara Golemon <pollita@php.net>\r
14  * @version     $Revision: 1.1 $\r
15  * @since       PHP 5.0.0\r
16  * @require     PHP 4.0.0 (user_error)\r
17  */\r
18 function php_compat_bcpowmod($x, $y, $modulus, $scale = 0)\r
19 {\r
20     // Sanity check\r
21     if (!is_scalar($x)) {\r
22         user_error('bcpowmod() expects parameter 1 to be string, ' .\r
23             gettype($x) . ' given', E_USER_WARNING);\r
24         return false;\r
25     }\r
26 \r
27     if (!is_scalar($y)) {\r
28         user_error('bcpowmod() expects parameter 2 to be string, ' .\r
29             gettype($y) . ' given', E_USER_WARNING);\r
30         return false;\r
31     }\r
32 \r
33     if (!is_scalar($modulus)) {\r
34         user_error('bcpowmod() expects parameter 3 to be string, ' .\r
35             gettype($modulus) . ' given', E_USER_WARNING);\r
36         return false;\r
37     }\r
38 \r
39     if (!is_scalar($scale)) {\r
40         user_error('bcpowmod() expects parameter 4 to be integer, ' .\r
41             gettype($scale) . ' given', E_USER_WARNING);\r
42         return false;\r
43     }\r
44 \r
45     $t = '1';\r
46     while (bccomp($y, '0')) {\r
47         if (bccomp(bcmod($y, '2'), '0')) {\r
48             $t = bcmod(bcmul($t, $x), $modulus);\r
49             $y = bcsub($y, '1');\r
50         }\r
51 \r
52         $x = bcmod(bcmul($x, $x), $modulus);\r
53         $y = bcdiv($y, '2');\r
54     }\r
55 \r
56     return $t;    \r
57 }\r
58 \r
59 \r
60 // Define\r
61 if (!function_exists('bcpowmod')) {\r
62     function bcpowmod($x, $y, $modulus, $scale = 0)\r
63     {\r
64         return php_compat_bcpowmod($x, $y, $modulus, $scale);\r
65     }\r
66 }\r
67 ?>