Theory Of Numbers
The Set:
Z(p) = { 0 , 1 , 2 , 3 , 4 , . . . , p-1 }
Is called the set of integers modulo p (or mod p for short). It is a set that contains Integers from 0 up until p-1.
Example: Z10={0,1,2,3,4,5,6,7,8,9}
A multiplicative inverse for x is a number that when multiplied by x, will equal 1. The multiplicative inverse of x is written as x-1 and is defined as so:
x . x-1 = 1
The greatest common divisor (gcd) between two numbers is the largest integer that will divide both numbers. For example, gcd(4,10)=2.
The interesting thing is that if two numbers have a gcd of 1, then the smaller of the two numbers has a multiplicative inverse in the modulo of the larger number.
Example: Lets work in the set Z9, then 4 ∈ Z9 and gcd(4 , 9) = 1. Therefore 4 has a multiplicative inverse (written 4-1) in mod 9, which is 7. And indeed, 4 . 7 = 28 = 1 mod 9. But not all numbers have inverses. For instance, 3 ∈ Z9 but 3-1 does not exist! This is because gcd(3 , 9)=3 ≠ 1.
Euler's Totient is the number of elements that have a multiplicative inverse in a set of modulo integers. The totient is denoted using the Greek symbol phi ϕ.the totient is just the count of the number of elements that have their gcd with the modulus equal to 1. This brings us to an important equation regarding the totient and prime numbers:
p ∈ P , ϕ(p) = (p-1)
EXAMPLE : ϕ(7) = |{0 , 1 , . . . , 6 }| = 6
With the above background, we have enough tools to describe RSA and show how it works. RSA is actually a set of two algorithms:
The key generation algorithm is the most complex part of RSA. The aim of the key generation algorithm is to generate both the public and the private RSA keys. Sounds simple enough! Unfortunately, weak key generation makes RSA very vulnerable to attack. So it has to be done correctly. Here is what has to happen in order to generate secure RSA keys
This is the process of transforming a plaintext message into ciphertext, or vice-versa. The RSA function, for message m and key k is evaluated as follows:
F(m,k) = mk mod (n)
Encryption : F(m,e) = me mod n = c (cipher) where m is the message , e is the public key and n is modulus
Decryption : F(c,d) = cd mod n = m the message