This is a basic Python code to implement RSA Cryptography. The aim was to learn to code in Python and to learn about the RSA Cryptosystem.
- Firstly, Prime numbers are genereted using
primegeneration.py. - The generated data is then inserted wherever necessary (see below) in the
encryption.pyanddecryption.pyfiles. The prime numbers generated are not huge though they are each around 8 digits long. But for an illustration this serves the purpose. The prime number generation can be made faster using Rabin-Miller Primality testing. - The
encryption.pyfile is to be run next. Before that one has to paste thepublic keyasekeyand themodulusasmodulus(both at the top of theencryption.pyfile) from theprimegeneration.pyexecution. - The text to be encrypted is input. At present only alphabets, digits and spaces are supported. One can modify that.
- Then padding is done to further show how it is done in the real world.
- Then the message is encrypted and converted to hexadecimal text. The output is a hexadecimal stream of characters.
- Then one has to provide this stream of characters as input for the
decryption.pyfile but... - But firstly one has to copy the values of
private keyasdkey,modulusasmodulus,prime numbers,paspandqasq(all at the top of thedecryption.pyfile) from the earlierprimegeneration.pyexecution. - Then after providing the input, the stream of characters is decoded and the message is shown. This may take some time as the decryption is not optimized and uses the basic Chinese Reminder Theorem.
So the commands and the order of execution is :
python primegeneration.pypython encryption.pypython decryption.py