Ejemplo n.º 1
0
 public static function convert($number, $inputFormat = DiffieHellman::FORMAT_NUMBER, $outputFormat = DiffieHellman::FORMAT_BINARY)
 {
     $math = Math\BigInteger\BigInteger::factory();
     if ($inputFormat == $outputFormat) {
         return $number;
     }
     // convert to number
     switch ($inputFormat) {
         case DiffieHellman::FORMAT_BINARY:
         case DiffieHellman::FORMAT_BTWOC:
             $number = $math->binToInt($number);
             break;
         case DiffieHellman::FORMAT_NUMBER:
         default:
             // do nothing
             break;
     }
     // convert to output format
     switch ($outputFormat) {
         case DiffieHellman::FORMAT_BINARY:
             return $math->intToBin($number);
             break;
         case DiffieHellman::FORMAT_BTWOC:
             return $math->intToBin($number, true);
             break;
         case DiffieHellman::FORMAT_NUMBER:
         default:
             return $number;
             break;
     }
 }
Ejemplo n.º 2
0
 public function getUserIdFromHash()
 {
     $code = $this->getCode();
     $bigInt = BigInteger::factory('bcmath');
     $userId = \Eva\Stdlib\String\Hash::shortHash($code, true);
     $userId = $bigInt->sub($userId, '100000000');
     return $userId;
 }
Ejemplo n.º 3
0
 public function formBigInteger()
 {
     $bigInt = BigInteger::factory('bcmath');
     $x = Rand::getString(100, '0123456789');
     $y = Rand::getString(100, '0123456789');
     $sum = $bigInt->add($x, $y);
     $len = strlen($sum);
     $this->data->bigint = "{$x} + {$y} = {$sum}";
     $this->render();
 }
Ejemplo n.º 4
0
 public function setUp()
 {
     try {
         $math = BigInteger\BigInteger::factory();
     } catch (MathException $e) {
         if (strpos($e->getMessage(), 'math support is not detected') !== false) {
             $this->markTestSkipped($e->getMessage());
         } else {
             throw $e;
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @param mixed $value
  */
 public function __construct($value)
 {
     $this->value = BigIntegerMath::factory()->init($value, 10);
     $this->type = self::XMLRPC_TYPE_I8;
 }
Ejemplo n.º 6
0
 /**
  * Constructor; if set construct the object using the parameter array to
  * set values for Prime, Generator and Private.
  * If a Private Key is not set, one will be generated at random.
  *
  * @param string $prime
  * @param string $generator
  * @param string $privateKey
  * @param string $privateKeyFormat
  */
 public function __construct($prime, $generator, $privateKey = null, $privateKeyFormat = self::FORMAT_NUMBER)
 {
     $this->setPrime($prime);
     $this->setGenerator($generator);
     if ($privateKey !== null) {
         $this->setPrivateKey($privateKey, $privateKeyFormat);
     }
     // set up BigInteger adapter
     $this->math = Math\BigInteger\BigInteger::factory();
 }
Ejemplo n.º 7
0
 public function testFactoryUnknownAdapterRaisesServiceManagerException()
 {
     $this->setExpectedException('Zend\\ServiceManager\\Exception\\ExceptionInterface');
     BigInt::factory('unknown');
 }