Since things didn't work out between me and mbedtls, here are the basic encryption algorithms.
Diff: rsa-small-numbers.cpp
- Revision:
- 0:65a36a7b25d0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rsa-small-numbers.cpp Sat Nov 10 20:11:01 2018 +0000 @@ -0,0 +1,48 @@ +#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; +}