{"id":20279345,"url":"https://github.com/simplito/bigint-wrapper-php","last_synced_at":"2025-10-06T02:10:15.453Z","repository":{"id":29901775,"uuid":"123125991","full_name":"simplito/bigint-wrapper-php","owner":"simplito","description":"Fast common interface for php_gmp and php_bcmath modules","archived":false,"fork":false,"pushed_at":"2022-01-05T18:33:30.000Z","size":8,"stargazers_count":15,"open_issues_count":5,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-01T07:21:45.107Z","etag":null,"topics":["bcmath","bcmath-modules","biginteger","cryptography","encryption","gmp","php","php-gmp"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplito.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-27T12:28:14.000Z","updated_at":"2025-05-09T09:39:10.000Z","dependencies_parsed_at":"2022-08-03T11:45:57.938Z","dependency_job_id":null,"html_url":"https://github.com/simplito/bigint-wrapper-php","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/simplito/bigint-wrapper-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fbigint-wrapper-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fbigint-wrapper-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fbigint-wrapper-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fbigint-wrapper-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplito","download_url":"https://codeload.github.com/simplito/bigint-wrapper-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fbigint-wrapper-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278547821,"owners_count":26004775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bcmath","bcmath-modules","biginteger","cryptography","encryption","gmp","php","php-gmp"],"created_at":"2024-11-14T13:29:34.545Z","updated_at":"2025-10-06T02:10:15.425Z","avatar_url":"https://github.com/simplito.png","language":"PHP","readme":"\n# BigInteger wrapper library for PHP\n\n## Information\n\nThis library is a common interface for php_gmp and php_bcmath modules. It automatically detects supported modules and uses the best of them (gmp\u003ebcmath). Gmp is a lot faster, but is also missing on many hosting services -- that is why this wrapper has been created. It is used for example in encryption functions of the [PrivMX WebMail](https://privmx.com) software.  \n\n## Installation\n\nYou can install this library via Composer:\n```\ncomposer require simplito/bigint-wrapper-php\n```\n\n## Documentation\n\nIf you want to force using a specific implementation, then define constant S_MATH_BIGINTEGER_MODE - set it to \"gmp\" or \"bcmath\". If you do not do this, mode of operation and the constant will be set automatically.\n\nIf there are no gmp and bcmath modules, an exception will be thrown. If you want to prevent this, then simply define S_MATH_BIGINTEGER_QUIET constant.\n\nAll functions of this library are implemented as members of class BigInteger, which is located under BI namespace. Instances of BigInteger are immutable - member functions usually return new instances of the BigInteger class.\n\n\n### ConvertibleToBi - a placeholder type\n\nTo make the below documentation more readable we use the \"ConvertibleToBi\" type symbol, which in reality can be one of the following types:   \n- an instance of the BigInteger class\n- an integer\n- a decimal string\n- a gmp resource or class (only when you are in gmp mode)\n\nIf you have a non-decimal string and want to use it -- first you have to convert it to BigInteger class using:\n```\nnew BigInteger($myNonDecimalString, $baseOfMyNonDecimalString)\n```\n\n### BI\\BigInteger class members\n\n#### construct(ConvertibleToBi $value = 0, int $base = 10)\nCreates a new instance of BigInteger. If you pass an invalid value, an exception will be thrown. If $base === true then passed $value will be used without any check and conversion. Supported bases: 2, 10, 16, 256.\n- **GMP implementation:** gmp_init + bin2hex for 256 base\n- **Bcmath implementation:** custom(bcadd + bcmul)\n\n#### static BigInteger|false createSafe(ConvertibleToBi $value = 0, int $base = 10)\nCreates a new BigInteger instance in the same way as constructor, but if there is an error, false will be returned instead of throwing an exception.\n\n#### BigInteger add(ConvertibleToBi $x)\nAdds numbers\n- **GMP implementation:** gmp_add\n- **Bcmath implementation:** bcadd\n\n#### BigInteger sub(ConvertibleToBi $x)\nSubtracts numbers\n- **GMP implementation:** gmp_sub\n- **Bcmath implementation:** bcsub\n\n#### BigInteger mul(ConvertibleToBi $x)\nMultiplies numbers\n- **GMP implementation:** gmp_mul\n- **Bcmath implementation:** bcmul\n\n#### BigInteger div(ConvertibleToBi $x)\nDivides numbers\n- **GMP implementation:** gmp_div_q\n- **Bcmath implementation:** bcdiv\n\n#### BigInteger divR(ConvertibleToBi $x)\nReturns a remainder of the division of numbers. The remainder has the sign of the divided number.\n- **GMP implementation:** gmp_div_r\n- **Bcmath implementation:** bcmod\n\n#### array(BigInteger, BigInteger) divQR(ConvertibleToBi $x)\nDivides numbers and returns quotient and remainder. Returns an array(), with the first element being quotient, and the second being remainder.\n- **GMP implementation:** gmp_div_qr\n- **Bcmath implementation:** div + divR\n\n#### BigInteger mod(ConvertibleToBi $x)\nThe \"division modulo\" operation. The result is always non-negative, the sign of divider is ignored.\n- **GMP implementation:** gmp_mod\n- **Bcmath implementation:** custom (bcmod + bcadd)\n\n#### BigInteger gcd(ConvertibleToBi $x)\nCalculates greatest common divisor\n- **GMP implementation:** gmp_gcd\n- **Bcmath implementation:** custom (bccomp + bcdiv + bcsub + bcmul)\n\n#### BigInteger|false modInverse(ConvertibleToBi $x)\nInverses by modulo, returns false if inversion does not exist.\n- **GMP implementation:** gmp_invert\n- **Bcmath implementation:** custom (gcd)\n\n#### BigInteger pow(ConvertibleToBi $x)\nThe power function.\n- **GMP implementation:** gmp_pow\n- **Bcmath implementation:** bcpow\n\n#### BigInteger powMod(ConvertibleToBi $x, ConvertibleToBi $n)\nThe modular power function.\n- **GMP implementation:** gmp_powm\n- **Bcmath implementation:** bcpowmod\n\n#### BigInteger abs()\nReturns absolute value.\n- **GMP implementation:** gmp_abs\n- **Bcmath implementation:** check first character\n\n#### BigInteger neg()\nNegates the number\n- **GMP implementation:** gmp_neg\n- **Bcmath implementation:** check first character\n\n#### BigInteger binaryAnd(ConvertibleToBi $x)\nBitwise AND.\n- **GMP implementation:** gmp_and\n- **Bcmath implementation:** custom (toBytes + php string and)\n\n#### BigInteger binaryOr(ConvertibleToBi $x)\nBitwise OR\n- **GMP implementation:** gmp_or\n- **Bcmath implementation:** custom (toBytes + php string or)\n\n#### BigInteger binaryXor(ConvertibleToBi $x)\nBitwise XOR\n- **GMP implementation:** gmp_xor\n- **Bcmath implementation:** custom (toBytes + php string xor)\n\n#### BigInteger setbit($index, $bitOn = true)\nSets bit at given index\n- **GMP implementation:** gmp_setbit\n- **Bcmath implementation:** custom (toBits)\n\n#### bool testbit($index)\nTests if a bit at given index is set\n- **GMP implementation:** gmp_testbit\n- **Bcmath implementation:** custom (toBits)\n\n#### int scan0($start)\nScans for 0, and returns index of first found bit\n- **GMP implementation:** gmp_scan0\n- **Bcmath implementation:** custom (toBits)\n\n#### int scan1($start)\nScans for 1, and returns index of first found bit\n- **GMP implementation:** gmp_scan1\n- **Bcmath implementation:** custom (toBits)\n\n#### int cmp(ConvertibleToBi $x)\nCompares numbers, returns \u003c0, 0, \u003e0\n- **GMP implementation:** gmp_cmp\n- **Bcmath implementation:** bccomp\n\n#### bool equals(ConvertibleToBi $x)\nChecks if numbers are equal\n- **GMP implementation:** gmp_cmp\n- **Bcmath implementation:** bccomp\n\n#### int sign()\nSign of number, returns -1, 0, 1\n- **GMP implementation:** gmp_sign\n- **Bcmath implementation:** check first character\n\n#### int toNumber()\nConverts to number (use only with small 32/64bit numbers)\n- **GMP implementation:** gmp_intval\n- **Bcmath implementation:** intval\n\n#### string toDec()\nConverts to decimal string\n- **GMP implementation:** gmp_strval\n- **Bcmath implementation:** just the value\n\n#### string toHex()\nConverts to hex string\n- **GMP implementation:** gmp_strval\n- **Bcmath implementation:** toBytes + bin2hex\n\n#### string toBytes\nConverts to binary string\n- **GMP implementation:** gmp_strval + hex2bin\n- **Bcmath implementation:** custom (bcmod + bcdiv + bccomp)\n\n#### string toBits()\nConverts to bits string (0 and 1 characters)\n- **GMP implementation:** gmp_strval\n- **Bcmath implementation:** toBytes + decbin\n\n#### string toString(int $base = 10)\nConverts to string using given base (supported bases 2-62, 256)\n- **GMP implementation:** all above toX functions, and for non standard gmp_strval\n- **Bcmath implementation:** all above toX functions, and for non standard bcmod + bcdiv + bccomp\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplito%2Fbigint-wrapper-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplito%2Fbigint-wrapper-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplito%2Fbigint-wrapper-php/lists"}