I'm trying to apply the RSA cryptosystem to encrypt a byte M=72
, using predefined modulus n
, public key exponent e
and private key d
.
(n, e, d, p, q) = (4802, 5, 59, 43, 8)
In order to accomplish that, I used the following code on Python console:
C=(M**e)%n
M=(C**d)%n
print M
- the first instruction encrypts the byte as C: using the RSA encryption mathematical expression (
**
stands for exponentional, and%
for modulus in Python programming language) - the second decrypts C to get M back: using the RSA decryption mathematical expression.
However, the output shows:
2816
which means that M was incorrectly computed as '2816', although I'm pretty sure that all the values of n
, e
, d
, p
and q
respect the RSA public key algorithm specification.
Does anyone have any idea?
n
is some million (.. dozens words "million" suppressed) million times too small to provide security. B)M=(C**d)%n
won't work even if you increasen
by a million million. See modular exponentiation or/and use the three-argument form of pow. C) With the question's textbook RSA, a message guess can be checked; think of e.g. a name on the class roll. See encryption padding. $\endgroup$C**d
exactly forn
large enough for security, which implies nearly as largeC
andd
. Modular reduction must be applied as the exponentiation is performed. Three-argumentspow
does, but(C**d)%n
does not. On A):n
needs to be MUCH larger, otherwise it can be factored and an adversary can then decipher just as easily as the legitimate recipient. On C): with the question's textbook RSA, if you know that the name of a student is enciphered, you can encrypt each name on the class roll and see which matches the ciphertext. $\endgroup$