3,7 → 3,7 |
/* |
* PHP GMP-Supplement implemented using BCMath |
* Copyright 2020 Daniel Marschall, ViaThinkSoft |
* Version 2020-02-29 |
* Version 2020-04-07 |
* |
* Licensed under the Apache License, Version 2.0 (the "License"); |
* you may not use this file except in compliance with the License. |
162,8 → 162,8 |
// gmp_export ( GMP $gmpnumber [, int $word_size = 1 [, int $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN ]] ) : string |
// Export to a binary string |
function gmp_export($gmpnumber, $word_size = 1, $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN) { |
if ($word_size != 1) die("Word size != 1 not implemented"); |
if ($options != GMP_MSW_FIRST | GMP_NATIVE_ENDIAN) die("Different options not implemented"); |
if ($word_size != 1) throw new Exception("Word size != 1 not implemented"); |
if ($options != GMP_MSW_FIRST | GMP_NATIVE_ENDIAN) throw new Exception("Different options not implemented"); |
|
bcscale(0); |
$gmpnumber = bcmul($gmpnumber,"1"); // normalize |
232,8 → 232,8 |
function gmp_import($data, $word_size=1, $options=GMP_MSW_FIRST | GMP_NATIVE_ENDIAN) { |
bcscale(0); |
|
if ($word_size != 1) die("Word size != 1 not implemented"); |
if ($options != GMP_MSW_FIRST | GMP_NATIVE_ENDIAN) die("Different options not implemented"); |
if ($word_size != 1) throw new Exception("Word size != 1 not implemented"); |
if ($options != GMP_MSW_FIRST | GMP_NATIVE_ENDIAN) throw new Exception("Different options not implemented"); |
|
return gmp_init(hex2bin(gmp_strval(gmp_init($data), 16))); |
} |
760,7 → 760,6 |
$length = max(strlen($ab), strlen($bb)); |
$ab = str_pad($ab, $length, "0", STR_PAD_LEFT); |
$bb = str_pad($bb, $length, "0", STR_PAD_LEFT); |
|
// Do the bitwise binary operation |
$cb = ''; |
for ($i=0; $i<$length; $i++) { |