Groups of 3 decimals returns only 2 when using uppercase carectere

Asked

Viewed 20 times

0

Galera is the following trying to encode a message with RSA, and for that precise convert the characters to decimals and group them in 3 in an array to then do the calculations. But I am going through the following problem after pre-encoding the characters to the ASCII decimals and tries to group them into groups of 3 the uppercase characters if composed by only 2 digits they are only in 2 digits. Follow 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 ?

  • related (for reference): http://answall.com/questions/168087/loop-infinito-ao-gerar-a-chave-publica-do-rsa

  • 1

    Could not use openssl? See for help: http://stackoverflow.com/questions/31922094/php-rsa-key-creation

  • I’m doing this to study the same algorithm.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.