# Computing Math Using Python: RSA Cryptosystem ( 1 of 2)

One of the courses that I am currently taking is computing math with Python.

Easy part: I have learned various mathematical theorems and methods.

Hard part: It would have to be transferring my knowledge to Python code.

The current topic of the week is RSA Cryptosystem which is  a very interesting subject. It involves encrypting  and decrypting code.

Here are the following conditions that required for the code:

Public and Private Keys

1. Pick two prime numbers.
• p and q are considered as prime numbers. It is recommended to use huge values. (I started out small in the beginning by have p = 2 and q = 7.)
2. N will be the value provided after multiplying p and q.
3. Determine Φ(N).
• Instead of going through the process of finding the coprimes, the easier method to use is (p – 1)(q – 1) = Φ(N).  When having to use huge primes, this will lessen the process.

Encryption

1. Determine the value for e (this is for encryption).
• To finding eit involves two conditions as well.
• The  value of e cannot be less than 1 or more than Φ(N). ( 1 < e < Φ(N) )
• It requires to be coprimes with both N and Φ(N).
• Public key  = (e, N)

Decryption

1. Determine the value for d (this is for decryption).
• This process requires to actually choose the value for d and also using the modulus of Φi(N):  (d*e)( mod Φ(N).
• Private key = (d, N)

Math Results (Knowledge Part):

• p = 2 and q = 7
• N = (2)(7) = 14
• Φ(N) = (p – 1)(q – 1) = (2 – 1)(7 – 1) = 6
• Finding e:
• 1 < e < Φ(N) —> 1 < e < 6: The range  is [  1, 2, 3, 4,  5 ].
• The even numbers had to be excluded due to their relationship with N.
• The number 1 is not included due to being able to divide any number.
• Need to be coprime for both N and Φ(N) which will be 5.
• The number 3 was excluded to have a relationship with Φ(N).  3 divides 6 or another way 3|6.
• My public key is  (e, N) which is (5, 14). This is also part of my encryption that will discussed later.
• Choosing the value of d:
• (e * d)(mod Φ(N)) = 1  or 5d mod 6 = 1. By using this method, we will choose 11 to be d.
• My private key is (d, N) which is (11, 14).