title: Miller Rabin Primality test
body: <p>I have wrote a Miller Rabin primality test in C sharp, but it return false on every input.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>    static Boolean MilRab(UInt64 n)
      {
          UInt64[] ar = new UInt64[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
          for (int i = 0; i &lt; 10; i++)
          {
              if (Tanu(ar[i], n) == true) return false;
          }
          return true;
      }//MilRab
  
      static Boolean Tanu(UInt64 a, UInt64 n)
      {
          UInt64 b = n - 1;
          UInt64 d = 1;
          UInt64 x;
          Int16 i;
          for (i = 63; i &gt;= 0; i--) if (((b &gt;&gt; i) &amp; 1) == 1) break;
  
          for (;i&gt;=0;i--)
          {
              x = d;
              d = ((d * d) % n);
              if (d == 1 &amp;&amp; x != 1 &amp;&amp; x != n - 1) return true;
              if (b&gt;&gt;i == 1) d = (d * a) % n;
          }
          if (d != 1) return true;
        return false;
      }//Tanu
  </code></pre>
  
  <p>What do you think the problem can be? I spent a hole day debugging and its driving me crazy. Thank you.</p>