Modular Algorithm calculation error
<p>I have a program use Modular Exponentiation to calculate 7^644 mod 645, 11^644 mod 645, 3^2003 mod 99, 123^1001 mod 101. I follow the rules of Modular Exponentiation and then when I compile my result is wrong, The result for the output should be 436,1,22,27, but my output is way off. when i run my answer is 643, 655,20,39</p>

<p>This is My code:</p>

<pre><code>int Modulo(int b, int e, int m)
{

int remainder;//set the remainder of the procedure
int x = 1;// modular initially sets x = 1

//while loop to request the multiplication
while ( e != 0)
{

    remainder = e % 2;
    e = e/2;

    //Algorithm steps
    if(remainder == 1)//if remainder = 1 
    x = ( x * b) % m;//then x = (x · power) % m
    b = ( b * b) % m;//power = (power * power) % m

}
return x;


}
int main()
 {

  int b, e, m, modulo;//declares the variables 
  start:cout&lt;&lt;"Enter the base: ";//output for base
  cin&gt;&gt;b;

  cout&lt;&lt;"Enter the exponent: ";//output for exponent
  cin&gt;&gt;e;

  cout&lt;&lt;"Enter the number of modular: ";//output for mod
  cin&gt;&gt;m;

  modulo = b^e % m;//requesting the formula of Modular Exponentiation
  cout&lt;&lt;"The answer is \n"&lt;&lt;modulo&lt;&lt;endl;
  cin.get();
  // I create if statement to allow the user to restart the application 
//enter new value to see the different output
    char c;
    cout&lt;&lt;"Would you like to enter a new value? yes or no ";
    cin&gt;&gt; c;
    if(( c == 'Y') ||(c == 'y'))goto start ;//start is the label in the start of program
  return 0;
 }
</code></pre>
