Salut, j'ai un problème avec un modulo(testé avec % et la fonction fmod) qui me retourne toujours un 0 alors que à la calculatrice j'ai un résultat différent. Je cherche mais je vois pas pour quoi, une idée ? (ligne 146 à 156)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
$nbPremierfirst = rand(1,600);
$nbPremiersecond = rand(1,600);
try
{
	$bdd = new PDO('mysql:host=localhost;dbname= ;charset=utf8', ' ', ' ');
}
catch (Exception $c)
{
	die('Erreur : ' . $c->getMessage());
}
 
$reponse = $bdd->query('SELECT * FROM nb_premier');
$donnees = $reponse->fetch();
for($i = 0; $i < $nbPremierfirst; $i++){
	$donnees = $reponse->fetch();
}
$p = $donnees['nb'];
 
$reponse->closeCursor();
 
$reponse = $bdd->query('SELECT * FROM nb_premier');
$donnees = $reponse->fetch();
for($i = 0; $i < $nbPremiersecond; $i++){
	$donnees = $reponse->fetch();
}
$q = $donnees['nb'];
 
$reponse->closeCursor();
 
$n =$p*$q;
 
$m = ($p-1)*($q-1);
 
if($p < $q){
	$c = $q;
}
 
if($p > $q){
	$c = $p;
}
 
function PGCD($a, $b) {
 
    if (is_numeric($a) AND is_numeric($b)) {
 
        if ($b<$a AND $a!=0) {
 
            $reste = $a%$b;
 
            while ($reste!=0) {
 
                $reste = $a%$b;
                $a = $b;
                $b = $reste;
 
            }
 
            $resultat = $a;
 
        }
 
        elseif ($a<$b AND $b!=0) {
 
            $reste = $a%$b;
 
            while ($reste!=0) {
 
                $reste = $b%$a;
                $b = $a;
                $a = $reste;
 
            }
 
           $resultat = $b;
 
        }
 
        elseif ($a=$b) {    
 
            $premier = $deuxieme;
            $resultat = $a;
 
        }
 
        else {
 
            $resultat = FALSE;
 
        }
    }
	return $resultat;
}
 
 
 
$rep = 0;
 
while($rep != 1){
	$c++;
	$rep = PGCD($c,$m);
 
}
 
function bezout($a,$b){
	$r = 1;
	$u = 1;
	$v = 0;
	$x = 0;
	$y = 1;
	while($r != 0){
		$k = $a/$b;
		$q = intval($k);
		$r = $a%$b;
		$a = $b;
		$b = $r;
		$s = $u-$x*$q;
		$u = $x;
		$x = $s;
		$t = $v-$y*$q;
		$v =$y;
		$y = $t;	
	}
	return $u;
}
 
 
$u = bezout($c,$m);
// $k = 3;
// if($u < 0){
	// while($u < 0){
		// $u = $u-$k*$m;
		// $k++;
	// }
// }
 
echo "p =" . $p . "<br />";
echo "q =" . $q . "<br />";
echo "n =" . $n . "<br />";
echo "m =" . $m . "<br />";
echo "c =" . $c . "<br />";
echo "u =" . $u . "<br />";
 
 
$chaine = 'coucou !';
$ascii = ' ';
$longueur=strlen($chaine);
for($i=0;$i<$longueur;$i++)
{
$caractere=substr($chaine,$i,1);
echo "code ascii ".$caractere." ".ord($caractere)."<br>";
$carac = ord($caractere);
$puissance = pow($carac,$c);
$mod = fmod($puissance,$n);
$ascii .= $mod . ' ';
}
echo $ascii;
 
?>