Example #1
0
 protected static function toBitArray($string)
 {
     $result = new BitArray();
     for ($i = 0; $i < strlen($string); $i++) {
         if ($string[$i] == 'X') {
             $result->append(1);
         } elseif ($string[$i] == '.') {
             $result->append(0);
         }
     }
     return $result;
 }
Example #2
0
 public function testAppend()
 {
     $array = new BitArray(2);
     $array->append(0x7, 3);
     $this->assertEquals(5, $array->getLength());
     $this->assertEquals(array(0, 0, 1, 1, 1), $array->asArray());
 }
Example #3
0
 public function appendTo(BitArray $bitArray, array $text)
 {
     for ($i = 0; $i < $this->shiftByteCount; $i++) {
         if ($i == 0 || $i == 31 && $this->shiftByteCount <= 62) {
             $bitArray->append(31, 5);
             if ($this->shiftByteCount > 62) {
                 $bitArray->append($this->shiftByteCount - 31, 16);
             } elseif ($i == 0) {
                 $bitArray->append(min($this->shiftByteCount, 31), 5);
             } else {
                 $bitArray->append($this->shiftByteCount - 31, 5);
             }
         }
         $bitArray->append(ord($text[$this->shiftStart + $i]), 8);
     }
     return $bitArray;
 }
Example #4
0
 public function encode($data)
 {
     $result = new BitArray();
     while (strlen($data) >= 32) {
         $chunkLength = min(strlen($data), 2048 + 32 - 1);
         $result->append(self::CODE_UPPER_BS, 5);
         $result->append(0, 5);
         $result->append($chunkLength - 32, 11);
         $result->appendBytes(substr($data, 0, $chunkLength));
         $data = substr($data, $chunkLength);
     }
     if (strlen($data) > 0) {
         $result->append(self::CODE_UPPER_BS, 5);
         $result->append(strlen($data), 5);
         $result->appendBytes($data);
     }
     return $result;
 }
Example #5
0
 public static function generateCheckWords(BitArray $stuffedBits, $totalSymbolBits, $wordSize)
 {
     $messageSizeInWords = intval(($stuffedBits->getLength() + $wordSize - 1) / $wordSize);
     for ($i = $messageSizeInWords * $wordSize - $stuffedBits->getLength(); $i > 0; $i--) {
         $stuffedBits->append(1);
     }
     $totalSizeInFullWords = intval($totalSymbolBits / $wordSize);
     $messageWords = self::bitsToWords($stuffedBits, $wordSize, $totalSizeInFullWords);
     $rs = new ReedSolomonEncoder(self::getGF($wordSize));
     $messageWords = $rs->encodePadded($messageWords, $totalSizeInFullWords - $messageSizeInWords);
     $startPad = $totalSymbolBits % $wordSize;
     $messageBits = new BitArray();
     $messageBits->append(0, $startPad);
     foreach ($messageWords as $messageWord) {
         $messageBits->append($messageWord, $wordSize);
     }
     return $messageBits;
 }
Example #6
0
 public function appendTo(BitArray $bitArray, array $text)
 {
     $bitArray->append($this->value, $this->bitCount);
     return $bitArray;
 }