aboutsummaryrefslogtreecommitdiff
path: root/final/rsa-code.tex
blob: 64a0a478afd30cf8518cc51ca31820c08811af22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
The code for RSA encryption and decryption can be found in this folder at {\tt rsa-encrypt.py} and {\tt rsa-decrypt.py}.
{\tt rsa-encrypt} relies completely on user input, allowing the user to input a semiprime of arbitrary size (larger is more secure) and a value $e$ which must be coprime with one less both divisors of the semiprime ($p-1$ and $q-1$).
However, other than basic input and type conversion (string to list of integers to list of integers, for example), the ``heavy-lifting'' it does is very limited.
{\tt\par
def decrypt\_block(blk):\par
\hskip .25in return blk**d \% n\par
}
defines the majority of it, specifically the application of Euler's theorem.


Similarly, decryption relies on the basic principle of Euler's theorem to develop the decryption value $d$ (and the fact that that value can exist).
While efficiency was not absolutely necessary, it could be improved by using a speedier (Euclidean algorithm-based) decision algorithm for $d$ than simply checking all values.
This was neglected to focus on the real interesting component of RSA.
Once that value $d$ is available, the decryption can be known easily
In this case,
{\tt\par
def encrypt\_block(blk):\par
\hskip .25in return (blk ** e) \% n\par
}
defines the heavy lifting of ``undoing'' the RSA encryption, and shows how RSA shines in its simplicity---in stark contrast with its convoluted comrades.