Tks to allanino for the help with the math part.
rsa.exec - is an example how to use the code.
rsa.c - functions to generate the modulus, public and private keys, to crypt and decrypt things.
make - you can compile to use on terminal, or generate a static lib
obs: feel free to fork the project and use it, just mention the source.