3-decimal groups returns only 2 when using upper case

0

Galera is the next to trying to encode a message with RSA, and for this I need to convert the characters to decimals and group them into 3 in an array to then do the calculations. But I'm going through the following problem after pre-encoding the characters for the ASCII decimals and tries to group them into groups of 3 uppercase characters if they consist of only 2 digits they are only in 2 digits. Here is the code below:

<?php    
    $string = 'ThomSon';
    $valS = strlen($string);

    $code = '';
    $aCode = [];
    $valC = 0;

    $pi = 0;
    $pf = $valS - 1;
    for ($i = 1; $i <= $valS; $i ++) {
        array_push($aCode, ord(substr($string, $pi, -$pf)));
        $pi ++;
        $pf --;
    }
    $code = implode('', $aCode);
    $valC = strlen($code);

    $pi = 0;
    $pf = $valC - 3;

    $loop = true;
    for ($i = 1; $loop != false; $i ++) {
        if (implode('', $aCode) == $code) {
            $loop = false;
        } else {
            $frag = substr($code, $pi, -$pf);
            array_push($aCode, $frag);
            $pi += 3;
            $pf -= 3;
        }
    }

    echo $string . '<br>';
    echo $code . "<br>";

    for ($i = 0; $i < count($aCode); $i ++) {
        echo "<br>M($i) = {" . $aCode[$i] . "}";
    }

Does anyone know what it might be?

    
asked by anonymous 27.11.2016 / 17:23

0 answers