Ejemplo n.º 1
0
 private function errorCorrection()
 {
     if (DEBUG && DEBUG_LEVEL & EQR_EC) {
         $debug = true;
     } else {
         $debug = false;
     }
     //Generator polynomial for Reed-salomon error correction codewords
     $ecPolynomial[7] = array(0, 87, 229, 146, 149, 238, 102, 21);
     $ecPolynomial[10] = array(0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45);
     $ecPolynomial[13] = array(0, 74, 152, 176, 100, 86, 100, 106, 104, 130, 218, 206, 140, 78);
     $ecPolynomial[15] = array(0, 8, 183, 61, 91, 202, 37, 51, 58, 58, 237, 140, 124, 5, 99, 105);
     $ecPolynomial[16] = array(0, 120, 104, 107, 109, 102, 161, 76, 3, 91, 191, 147, 169, 182, 194, 255, 120);
     $ecPolynomial[17] = array(0, 43, 139, 206, 78, 43, 239, 123, 206, 214, 147, 24, 99, 150, 39, 243, 163, 136);
     $ecPolynomial[18] = array(0, 215, 234, 158, 94, 184, 97, 118, 170, 79, 187, 152, 148, 252, 179, 5, 98, 96, 153);
     $ecPolynomial[20] = array(0, 17, 60, 79, 50, 61, 163, 26, 187, 202, 180, 221, 225, 83, 239, 156, 164, 212, 212, 188, 190);
     $ecPolynomial[22] = array(0, 210, 171, 247, 242, 93, 230, 14, 109, 221, 53, 200, 74, 8, 172, 98, 80, 219, 134, 160, 105, 165, 231);
     $ecPolynomial[24] = array(0, 229, 121, 135, 48, 211, 117, 251, 126, 159, 180, 169, 152, 192, 226, 228, 218, 111, 0, 117, 232, 87, 96, 227, 21);
     $ecPolynomial[26] = array(0, 173, 125, 158, 2, 103, 182, 118, 17, 145, 201, 111, 28, 165, 53, 161, 21, 245, 142, 13, 102, 48, 227, 153, 145, 218, 70);
     $ecPolynomial[28] = array(0, 168, 223, 200, 104, 224, 234, 108, 180, 110, 190, 195, 147, 205, 27, 232, 201, 21, 43, 245, 87, 42, 195, 212, 119, 242, 37, 9, 123);
     $ecPolynomial[30] = array(0, 41, 173, 145, 152, 216, 31, 179, 182, 50, 48, 110, 86, 239, 96, 222, 125, 42, 173, 226, 193, 224, 130, 156, 37, 251, 216, 238, 40, 192, 180);
     $this->ecCw = cQRCode::getECTable($this->version, $this->errorLevel, EC_CW);
     $this->genPoly = $ecPolynomial[$this->ecCw];
     $this->initExp1 = cQRCode::getECTable($this->version, $this->errorLevel, CW_BLCK1) - 1;
     $this->initExp2 = cQRCode::getECTable($this->version, $this->errorLevel, CW_BLCK2) - 1;
     $this->ecBlck1 = cQRCode::getECTable($this->version, $this->errorLevel, BLOCK1);
     $this->ecBlck2 = cQRCode::getECTable($this->version, $this->errorLevel, BLOCK2);
     $index = 0;
     if ($debug) {
         printf("Error Correction Codewords %d<br>Block 1 Number of Error " . "Correction Blocks %d<br>Block 2 Number of Error Correction Blocks %d<br>", $this->ecCw, $this->ecBlck1, $this->ecBlck2);
     }
     $data1Len = cQRCode::getECTable($this->version, $this->errorLevel, CW_BLCK1) - $this->ecCw;
     for ($i = 1; $i <= $this->ecBlck1; $i++) {
         $dataBlck1[$i] = substr($this->strEncoded, $index, CW_BITS * $data1Len);
         if (isset($mssgPoly)) {
             unset($mssgPoly[$i]);
         }
         $mssgPoly[$i] = new cIPoly();
         if (isset($ecPoly1)) {
             unset($ecPoly1[$i]);
         }
         $ecPoly1[$i] = new cAPoly();
         //generate ecc polynomial
         for ($k = 0; $k < count($ecPolynomial[$this->ecCw]); $k++) {
             $ecPoly1[$i]->addTerm(new cATerm($ecPolynomial[$this->ecCw][$k], $this->initExp1 - $k));
         }
         $exp = $this->initExp1;
         //generate message polynomial
         for ($j = 0; $j < CW_BITS * $data1Len; $j += CW_BITS) {
             $coeff = bindec(substr($dataBlck1[$i], $j, CW_BITS));
             $mssgPoly[$i]->addTerm(new cITerm($coeff, $exp));
             $exp--;
         }
         if ($debug) {
             print "Generator polynomial (Block 1) " . $ecPoly1[$i] . "<br>";
             printf("Data Block 1, %d : <br>%s<br>Message polynomial= <br>%s<br>", $i, wordwrap($dataBlck1[$i], 64, "<br>", true), $mssgPoly[$i]);
         }
         $ecBlck1[$i] = $this->computeEC($ecPoly1[$i], $mssgPoly[$i]);
         if ($debug) {
             printf("Error Correction Block 1, %d : <br>%s<br>", $i, wordwrap($ecBlck1[$i], 64, "<br>", true));
         }
         $index += CW_BITS * $data1Len;
     }
     $data2Len = cQRCode::getECTable($this->version, $this->errorLevel, CW_BLCK2) - $this->ecCw;
     if ($this->ecBlck2 > 0) {
         for ($i = 1; $i <= $this->ecBlck2; $i++) {
             $dataBlck2[$i] = substr($this->strEncoded, $index, CW_BITS * $data2Len);
             unset($mssgPoly[$i]);
             $mssgPoly[$i] = new cIPoly();
             unset($ecPoly2[$i]);
             $ecPoly2[$i] = new cAPoly();
             //generate ecc polynomial
             for ($k = 0; $k < count($ecPolynomial[$this->ecCw]); $k++) {
                 $ecPoly2[$i]->addTerm(new cATerm($ecPolynomial[$this->ecCw][$k], $this->initExp2 - $k));
             }
             $exp = $this->initExp2;
             //generate message polynomial
             for ($j = 0; $j < CW_BITS * $data2Len; $j += CW_BITS) {
                 $coeff = bindec(substr($dataBlck2[$i], $j, CW_BITS));
                 $mssgPoly[$i]->addTerm(new cITerm($coeff, $exp));
                 $exp--;
             }
             if ($debug) {
                 print "Generator polynomial (Block 2) " . $ecPoly2[$i] . "<br>";
                 printf("Data Block 2, %d : <br>%s<br>Message polynomial= <br>%s<br>", $i, wordwrap($dataBlck2[$i], 64, "<br>", true), $mssgPoly[$i]);
             }
             $ecBlck2[$i] = $this->computeEC($ecPoly2[$i], $mssgPoly[$i]);
             if ($debug) {
                 printf("Error Correction Block 2, %d : <br>%s<br>", $i, wordwrap($ecBlck2[$i], 64, "<br>", true));
             }
             $index += CW_BITS * $data2Len;
         }
     }
     $finalSeq = "";
     if ($data1Len >= $data2Len) {
         $dataLen = $data1Len;
     } else {
         $dataLen = $data2Len;
     }
     //generate final sequence
     for ($i = 0; $i < $dataLen; $i++) {
         for ($j = 1; $j <= $this->ecBlck1; $j++) {
             if ($i * CW_BITS + CW_BITS <= strlen($dataBlck1[$j])) {
                 $finalSeq .= substr($dataBlck1[$j], $i * CW_BITS, CW_BITS);
             }
         }
         for ($j = 1; $j <= $this->ecBlck2; $j++) {
             if ($i * CW_BITS + CW_BITS <= strlen($dataBlck2[$j])) {
                 $finalSeq .= substr($dataBlck2[$j], $i * CW_BITS, CW_BITS);
             }
         }
     }
     for ($i = 0; $i < $this->ecCw; $i++) {
         for ($j = 1; $j <= $this->ecBlck1; $j++) {
             $finalSeq .= substr($ecBlck1[$j], $i * CW_BITS, CW_BITS);
         }
         for ($j = 1; $j <= $this->ecBlck2; $j++) {
             $finalSeq .= substr($ecBlck2[$j], $i * CW_BITS, CW_BITS);
         }
     }
     //add reminder bits
     if ($this->remBits > 0) {
         $finalSeq .= sprintf("%0" . $this->remBits . "b", 0);
     }
     $this->finalSeq = $finalSeq;
     if ($debug) {
         printf("Final sequence: <br>%s<br>", wordwrap($this->finalSeq, 64, "<br>", true));
     }
 }
Ejemplo n.º 2
0
<?php

/* Сниппет генерации QR-кода
*
*  @Author: Используется класс для создания QR - Omar Eduardo Ortiz Garza <*****@*****.**>
*  @Author: Serg28 (Тельный Сергей) <*****@*****.**>, http://tsvshop.xyz
*
*  Параметры:
*  &text - текст, который нужно закодировать в QR-код
*  &format - формат результирующего изображения: GIF|PNG|JPG по умолчанию GIF
*/
if (!defined('MODX_BASE_PATH')) {
    die('What are you doing? Get out of here!');
}
$text = !empty($text) ? $text : 'http://tsvshop.xyz';
$format = !empty($format) ? $format : 'GIF';
require_once MODX_BASE_PATH . "assets/snippets/TSVqr/cQRCode.php";
$qr = new cQRCode($text, ECL_L);
$qr->getQRImg(strtoupper($format), md5($text));
echo "/assets/snippets/TSVqr/tmp/" . md5($text) . "." . strtolower($format);
Ejemplo n.º 3
0
<?php

$args = explode('&', $_SERVER['QUERY_STRING']);
if (is_array($args) && count($args) > 0) {
    require_once "../lib/fbx/Fab/cQRCode.php";
    require_once "../lib/fbx/Fab/Base.php";
    $base = new \fbx\Fab\Base();
    if ($args[0] != '') {
        $finalFileName = $args[0];
        $linkSaveImg = $args[1];
        $urlIntoQrCode = $args[2] . "&" . $args[3] . "&" . $args[4] . "&" . $args[5];
        //        $urlIntoQrCode = $args[2];
        //        for ($i=0; $i<=count($args);$i++){
        //            if ($i>2){
        //                $urlIntoQrCode .= $urlIntoQrCode."&".implode('&',$args);
        //            }
        //        }
        $base->getWrLog($urlIntoQrCode, "QRcode link", "createQR", __FILE__);
        $completePathFilename = "{$linkSaveImg}/{$finalFileName}";
        $qr = new cQRCode("{$urlIntoQrCode}", ECL_L);
        $qr->getQRImg("PNG", $completePathFilename);
    }
    // http://192.168.1.51/labox/public/accueil ? login=mario &111=@@@ &languages=fr_FR
}