Since things didn't work out between me and mbedtls, here are the basic encryption algorithms.

rsa-small-numbers.cpp

Committer:
priyanshu_varshney
Date:
7 months ago
Revision:
0:65a36a7b25d0

File content as of revision 0:65a36a7b25d0:

#include<iostream>
#include<math.h>

int gcd(int a, int h)
{
    int temp;
    while (1)
    {
        temp = a%h;
        if (temp == 0)
          return h;
        a = h;
        h = temp;
    }
}

int main()
{
    double p = 3;
    double q = 7;
    double n = p*q;
    double e = 2;
    double phi = (p-1)*(q-1);
    while (e < phi)
    {
       
        if (gcd(e, phi)==1)
            break;
        else
            e++;
    }

    int k = 2; 
    double d = (1 + (k*phi))/e;

    double msg = 20;

    printf("Message data = %lf", msg);
    double c = pow(msg, e);
    c = fmod(c, n);
    printf("\nEncrypted data = %lf", c);

    double m = pow(c, d);
    m = fmod(m, n);
    printf("\nOriginal Message Sent = %lf", m);

    return 0;
}