RSA and Python
xnacly.me
xnacly.me
512-bit RSA has been breakable, by academics, since before this millennium.
> RSA number | Decimal digits | Binary digits | Cash prize offered | Factored on | Factored by
> RSA155 | 155 | 512 | US$9,383[8] | August 22, 1999 | Herman te Riele et al.
https://en.wikipedia.org/wiki/RSA_Factoring_Challenge
Further, according to authors of the paper factoring RSA-768 (bit), in 2009/10
> it would be prudent to phase out usage of 1024-bit RSA within the next three to four years. (p1, 2010)
My article isn't written as a step-by-step tutorial and doesn't come with example numbers. But mine fills in certain things that xnacly doesn't cover: random prime generation, efficiently calculating the decryption exponent d from (n, e) by using a modular inverse, using modular exponentiation instead of power-then-modulo.
By the way for Python, modular exponentiation is pow(x, y, m) (since 3.0), and modular inverse is pow(x, -1, m) (since 3.8, Oct 2019). https://docs.python.org/3/library/functions.html#pow
You're supposed to concatenate all the input numbers, to create a message that has hundreds or thousands of digits; then RSA-encrypt that number.
That's not how it works...
In modern protocols, you don't encrypt at all with RSA. You use a key exchange, and if you use RSA, you only use it as a signature algorithm to initiate the key exchange.
If you happen to want to encrypt with RSA, which you usually shouldn't, you first use a padding algorithm (the modern variant of that is called RSA-OAEP) with which you prepare and then encrypt a random key. That key you then use for symmetric encryption.