Exemplo n.º 1
0
function getPublicKey($tab = array(), $mod, $e, $block_limit)
{
    $length_tab = count($tab);
    $public_key = array();
    $key_inv_mod = inv_mod($e, $mod);
    $password_permut = array();
    // if (super_croissance_check($tab)) {
    for ($i = 0; $i < $length_tab; $i++) {
        $current_operation = $tab[$i] * $e;
        $modulo_operation = my_modulo($current_operation, $mod);
        array_push($public_key, $modulo_operation);
    }
    // ordonée sans changer la valeur de la clé
    natsort($public_key);
    // on fait un foreach pour trouver les valeurs de la clé
    foreach ($public_key as $key => $value) {
        array_push($password_permut, $key);
    }
    echo "\n                Alice garde precieusement le mot de passe : [ ";
    foreach ($password_permut as $index_pass) {
        echo $index_pass;
    }
    echo " ]\n";
    // on sort en modifiant les valeurs de l'index
    sort($public_key);
    echo "\n                Alice envoie une clé publique à Bernard : [ ";
    foreach ($public_key as $values_in_key) {
        echo $values_in_key, " ";
    }
    echo " ]\n";
    echo "\n                Et envoie la limite de block à Bernard : [ ", $block_limit, " ]\n";
    return [$public_key, $password_permut];
    // }
}
Exemplo n.º 2
0
function inv_mod($a, $n)
{
    if (is_numeric($a) == false || is_numeric($n) == false) {
        echo "Va t'acheter des doigts !\n";
        return 0;
    } else {
        $a_init = $a;
        $n_init = $n;
        $res = my_modulo($n, $a);
        if ($res == 1) {
            $test2;
            for ($i = 1; is_int($test2) != true; $i++) {
                $test = $n * $i + 1;
                $test2 = $test / $a;
            }
            return $test2;
        } else {
            if ($res == 0) {
                return 0;
            } else {
                while ($res != 1 && $res != 0) {
                    $n = $a;
                    $a = $res;
                    $res = my_modulo($n, $a);
                }
                if ($res == 0) {
                    echo "Va t'acheter des doigts !\n";
                    return 0;
                } else {
                    if ($res == 1) {
                        $test2 = null;
                        for ($i = 1; is_int($test2) != true; $i++) {
                            $test = $n_init * $i + 1;
                            $test2 = $test / $a_init;
                        }
                        return $test2;
                    }
                }
            }
        }
    }
}
Exemplo n.º 3
0
function decryptKey($tab = array(), $d, $mod)
{
    $bin_message = null;
    $tmp_array = array();
    $array_new = array();
    // parcours du tableau
    foreach ($tab as $message) {
        //calcul du resultat
        $tmp_result = $message * $d;
        // ajout dans le tableau accompagné de son modulo
        array_push($tmp_array, my_modulo($tmp_result, $mod));
    }
    return $tmp_array;
}