title: RSA Algorithm For Numbers and Char values
body: <p>I'm not a programming expert. I'm new to cryptography and I had gone through the security algorithm RSA. I wrote the code like this:</p>
  
  <pre><code>#include&lt;math.h&gt;
  #include&lt;iostream&gt;
  #include&lt;cmath&gt;
  #include&lt;Windows.h&gt;
  
  using namespace std;
  
  class rsacrypto
  {
      long publickey;
      long privatekey;
      long modl; //Modulus
  
      public :
      rsacrypto(); //To be used to just generate private and public keys.
      rsacrypto(long &amp;,long &amp;,long &amp;);//To be used just to generate private and public keys.
      rsacrypto(long key,long modulus) // Should be used when a data is to be encrypted or decrypted using a key.
      {
          publickey = privatekey = key;
          modl = modulus;
      }
  
      long ret_publickey()
      {
          return publickey;
      }
      long ret_privatekey()
      {
          return privatekey;
      }
      long ret_modulus()
      {
          return modl;
      }
  
      void encrypt(char *);
      void decrypt(char *);
      int genrndprimes(int, int);
      int genrndnum(int, int);
      int totient(int);
      int gcd (int, int);
      int mulinv(int, int);
      boolean isPrime(long);
  };
  
  rsacrypto::rsacrypto()
      {
          long p1,p2; //Prime numbers
          long n = 0; //Modulus
          long phi =0; //Totient value.
          long e = 0; //Public key exponent.
          long d = 0; //Private key exponent.
          p1 = genrndprimes(1,10);
          Sleep(1000);
          p2 = genrndprimes(1,10);
          n = p1*p2;
          phi = (p1-1)*(p2-1);
          e = genrndnum(2,(phi-1));
          while(gcd(e,phi)!=1)
          {
              e = genrndnum(2,(phi-1));
          }
          d = mulinv(e, phi);
          cout&lt;&lt;"Public Key=("&lt;&lt;e&lt;&lt;","&lt;&lt;n&lt;&lt;")"&lt;&lt;"\n";
          cout&lt;&lt;"Private Key=("&lt;&lt;d&lt;&lt;","&lt;&lt;n&lt;&lt;")"&lt;&lt;"\n";
          privatekey = e;
          publickey = d;
          modl = n;
          int m=11;
          int en=0, decr=0;
          //Encryption
          en=(long)pow((double)m,d)%n;
          cout&lt;&lt;en&lt;&lt;"\n";
          //Decryption
          decr=(long)pow((double)en,e)%n;
          cout&lt;&lt;decr;
  }
  /*
  void rsacrypto::encrypt(char *dat)
  {
      long siz = strlen(dat);
      for(long i=0;i&lt;siz;i++)
      {
          dat[i]=(long)pow((double)dat[i],publickey)%modl;
          cout&lt;&lt;i&lt;&lt;"="&lt;&lt;dat[i]&lt;&lt;"\n";
      }
  
  }
  
  void rsacrypto::decrypt(char *datn)
  {
      long sizz = strlen(datn);
      for(long i=0;i&lt;sizz;i++)
      {
          datn[i]=(long)pow((double)datn[i],privatekey)%modl;
      }
      cout&lt;&lt;datn;
  }*/
  int rsacrypto::mulinv(int a, int b)
  {
      int b0 = b, t, q;
      int x0 = 0, x1 = 1;
      if (b == 1) return 1;
      while (a &gt; 1) {
          q = a / b;
          t = b, b = a % b, a = t;
          t = x0, x0 = x1 - q * x0, x1 = t;
      }
      if (x1 &lt; 0) x1 += b0;
      return x1;
  }
  int rsacrypto::genrndprimes(int a, int b){
      long pivot;
      do{
          pivot= rand() % b + a;
          if (isPrime(pivot))
          return pivot;
      } while (1==1);
  }
  
  boolean rsacrypto::isPrime(long pivot) {
      if(pivot &lt;= 1)
          return false;
      int root = sqrt((double)pivot);
  
      //start at 2 because all numbers are divisible by 1
      for(int x = 2; x &lt;= root; x++)  //You only need to check up to and including the root
      {
          if(pivot % x == 0)
              return false;
      }
      return true;
  }
  int rsacrypto::genrndnum(int a, int b){
      long pivot;
      pivot= rand() % b + a;
      return pivot;
  }
  
  int rsacrypto::gcd ( int a, int b )
  {
    int c;
    while ( a != 0 ) {
       c = a; a = b%a;  b = c;
    }
    return b;
  }
  
  void main()
  {
      rsacrypto m;
      system("pause");
  }
  </code></pre>
  
  <p>But I would like to make this code work for hexa decimal values. I don't know how to do that. I'm not a programming expert. Any help would be sinscierly appreciated. Thankyou.</p>