Пример #1
0
 private function encodeTest($type, $data, $ecWords)
 {
     $field = GenericGF::getInstance($type);
     $encoder = new ReedSolomonEncoder($field);
     $messageExpected = array_merge($data, $ecWords);
     $paddedData = array_pad($data, count($data) + count($ecWords), 0);
     $result = $encoder->encode($data, count($ecWords));
     $this->assertEquals($messageExpected, $result);
     $resultPadded = $encoder->encodePadded($paddedData, count($ecWords));
     $this->assertEquals($messageExpected, $resultPadded);
 }
Пример #2
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;
 }