Пример #1
0
 public function testDecodeSpecial()
 {
     $data = array(array('', '0', ''), array('', '00', ''), array('3e', '25', ''), array('39', 'z', ''));
     foreach ($data as $datum) {
         $decoded = Base58::decode($datum[1]);
         $this->assertSame($datum[0], $decoded, sprintf('%s != %s', $datum[0], $decoded));
     }
 }
Пример #2
0
 /**
  * @param string $num
  * @return string exactly 25 bytes, as lower case hex
  */
 public static function decode($num)
 {
     $res = Base58::decode($num, self::$alphabet);
     return str_pad($res, 50, '0', STR_PAD_LEFT);
 }
Пример #3
0
 /**
  * Creates the device object with the unique device ID *$uid* and adds
  * it to the IPConnection *$ipcon*.
  *
  * @param string $uid
  * @param IPConnection $ipcon
  */
 public function __construct($uid, $ipcon)
 {
     $longUid = Base58::decode($uid);
     if (bccomp($longUid, '4294967295') > 0) {
         // Convert from 64bit to 32bit
         $value1a = (int) bcmod($longUid, '65536');
         $value1b = (int) bcmod(bcdiv($longUid, '65536'), '65536');
         $value2a = (int) bcmod(bcdiv($longUid, '4294967296'), '65536');
         $value2b = (int) bcmod(bcdiv($longUid, '281474976710656'), '65536');
         $shortUid1 = $value1a & 0xfff;
         $shortUid1 |= ($value1b & 0xf00) << 4;
         $shortUid2 = $value2a & 0x3f;
         $shortUid2 |= ($value2b & 0xf) << 6;
         $shortUid2 |= ($value2b & 0x3f00) << 2;
         $this->uid = bcadd(bcmul($shortUid2, '65536'), $shortUid1);
     } else {
         $this->uid = $longUid;
     }
     $this->ipcon = $ipcon;
     for ($i = 0; $i < 256; ++$i) {
         $this->responseExpected[$i] = self::RESPONSE_EXPECTED_INVALID_FUNCTION_ID;
     }
     $this->responseExpected[IPConnection::FUNCTION_ENUMERATE] = self::RESPONSE_EXPECTED_ALWAYS_FALSE;
     $this->responseExpected[IPConnection::CALLBACK_ENUMERATE] = self::RESPONSE_EXPECTED_ALWAYS_FALSE;
     $ipcon->devices[$this->uid] = $this;
     // FIXME: use a weakref here
 }