title: 142^23%187 modulo RSA should be 65 but is 53 any idea why?
body: <p>As in title, 142^23%187 should be 65 not 53.
  It is part of RSA encrypting/decrypting algorithm.</p>
  
  <p>Previous modulo operation is correct but secon one is not.</p>
  
  <p>If u type 142^23%187 in wolphram alpha is correct 65 - and 65 is indeed A after decrypting.</p>
  
  <p>Any ideas?
  Code below:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  
  namespace RSA
  {
      class Program
      {
          static void Main(string[] args)
          {
              Console.WriteLine("Hello World!");
  
  
  
              AlgoritmRSA RSA = new AlgoritmRSA(11, 17, 7);
              RSA.Encrypting("A");
              RSA.Decrypting();
  
  
  
          }
      }
  }
  
  namespace RSA
  {
      public class AlgoritmRSA
      {
  
          public AlgoritmRSA(int p, int q, int e) 
          {
              this.P = p;
              this.Q = q;
              this.E = e;
  
          }
          public int P { get; private set; }
          public int Q { get; private set; }
          public int E { get; private set; }
  
          List&lt;int&gt; J = new List&lt;int&gt;();
          List&lt;double&gt; C = new List&lt;double&gt;();
          List&lt;double&gt; NJ = new List&lt;double&gt;();
          List&lt;char&gt; ASCIIList = new List&lt;char&gt;();
  
          public void Encrypting(string message)
          {
              int n = P * Q;
              System.Console.WriteLine("N = {0}",n);
  
              foreach (var item in message)
              {
                  J.Add(Convert.ToInt32(item));
              }
  
              System.Console.WriteLine("E = {0}", E);
  
              foreach (var item in J)
              {
                  System.Console.WriteLine("J = {0}", item);
                  C.Add(Math.Pow(item, E) % n);
                  System.Console.WriteLine("C = {0}", C[0]);
              }
  
          }
  
  
          public void Decrypting()
          {
              double CC = Math.Pow(142, 23);
              double BB = CC % 187;
              System.Console.WriteLine(CC);
  
  
              int n  = P * Q;
  
              int K = ((P-1)*(Q-1)+1)/E;
              System.Console.WriteLine("K = {0}", K);
  
  
              foreach (var enc in C)
              {
                  NJ.Add(Math.Pow(enc, K) % n);
                  System.Console.WriteLine("NJ = {0}", NJ[0]);
              }
  
              foreach (var item in NJ)
              {
                  ASCIIList.Add(Convert.ToChar(item));
  
              }
  
              System.Console.WriteLine("Encrypted Message: \n");
  
              foreach (var item in ASCIIList)
              {
                  System.Console.WriteLine("{0}", item);
              }
  
  
          }
  
      }
  }
  </code></pre>