
It cannot be implemented using floating points numbers (double) – or, at least, not reasonably, since the “divisions” that occur in RSA refer to multiplicative inverses in modular arithmetic – which is very different from divisions of floating point numbers (and there is absolutely no gain from using floating point numbers – RSA requires the exact representation of any number from 0 up to the modulus – clearly a job for integral types).
RSA CRYPTEXT DECODER MOD
RSA is an algorithm that works with integers mod m.
RSA CRYPTEXT DECODER CODE
However, thats not too crucial.Īs a mathematician and programmer, I can confidently tell you that this is not RSA! There are a number of sites with this same code (possibly copies of this?), but it’s utterly incorrect. My last point: The totient doesn’t need to be (p-1)*(q-1) but only the lowest common multiple of (p-1) and (q-1). If your implementation of RSA gets public, everyone could derive some of the factors of (p-1)*(q-1) from e which would make RSA immediately less secure. e will always be the smallest number which is coprime to (p-1)*(q-1). e is supposed to be a random integer between 1 and n where n is p*q, but you are in fact not choosing it randomly but with a clear system. The last flaw I spotted is your way of choosing e. Thus d is the modular multiplicative inverse of e mod(totient) an can be calculated with the extended euclidian algorithm. k is arbitrary and should not be set to a fixed number like you did. The formula e*d = 1 + k * totient is correct but I think you misunderstood what it implies. The next thing is that your way of computing the private key d is wrong. First of all, I wouldn’t use the type double for values which are supposed to be integers, since integers are more precise than doubles when dealing with integers. But you can’t use it for an actual implementation of RSA since you wouldn’t be able to store numbers in the range of typical RSA public keys (n is somewhere between 20 bits).Īnd there are a few minor flaws in your code. It is nice to play and fiddle around with and to test how RSA works. To be fair, your code is quite simple and easy to understand. Printf("\nOriginal Message Sent = %lf",m) Ĭout<<"\n"<<"Original Message sent = "<

RSA algorithm is an asymmetric cryptographic algorithm as it creates 2 different keys for the purpose of encryption and decryption.

RSA Algorithm is used to encrypt and decrypt data in modern computer systems and other electronic devices.

Here you will learn about RSA algorithm in C and C++.
