ðŸŽ¯**What is RSA encryption?**

ðŸ‘‰RSA (Rivest-Shamir-Adleman) is an algorithm used for secure data transmission. It is an asymmetric encryption that is widely used for secure data transmission.

ðŸ‘‰In RSA, each person has a pair of keys: a public key and a private key.

ðŸ‘‰The public key can be shared with anyone, while the private key must be kept secret.

ðŸ‘‰When a message is sent using RSA, the sender encrypts the message using the recipient's public key.

ðŸ‘‰The recipient then decrypts the message using their private key.

ðŸ‘‰This ensures that only the intended recipient can read the message, as only they have the private key needed to decrypt it.

ðŸ“Œ**A simple demonstration of how the RSA algorithm works**

ðŸŒ²Suppose Swetha wants to send a secure message to Vijay.

ðŸŒ²Vijay generates a pair of keys using the RSA algorithm and sends his public key to Swetha.

ðŸŒ²Swetha uses Vijay's public key to encrypt her message and sends the encrypted message (ciphertext) to Vijay.

ðŸŒ²Vijay then uses his private key to decrypt the ciphertext and read the original message (plaintext).

ðŸ“Œ**Key generation:**

ðŸŒ²Vijay selects two prime numbers, p, and q, and calculates n = p **q and in this example, p = 5 and q = 11, so n = 5* *11 = 55.

ðŸŒ²Vijay calculates a value called the totient, denoted as Ï†(n), which is the number of positive integers less than n that are relatively prime to n. In this case, Ï†(55) = (p - 1) *(q - 1) = 4* *10 = 40.

ðŸŒ²The factors of 40 are 2*2*2*5.

ðŸŒ²Vijay selects a public key, e, that is relatively prime to Ï†(n) and none of the factors of 2 and 5. In this example, let's say e =7.

ðŸŒ²Vijay calculates his private key, d, such that e *d â‰¡ 1 (mod Ï†(n)) or we can derive d= (1+ x* Ï†(n))/e while x can be 0,1,2, 3, etc.

After some calculations using Excel, d is calculated as d = (1+4*40)/7 = 23.

ðŸŒ²We now have n=55, e=7, d=23

ðŸŒ²Vijay's public key is the pair (e, n), and his private key is the pair (d, n). Vijay sends his public key to Swetha.

ðŸ“Œ**Encryption:**

ðŸŒ²Swetha wants to send the message "HELLO" to Vijay.

ðŸŒ²She converts the message using a predetermined scheme (e.g., A=1, B=2, till Z=26.).

ðŸŒ²Swetha calculates the ciphertext, c, using the formula c â‰¡ m^e (mod n), where m is the plain text.

ðŸŒ²In this case, c is calculated as c = 8^7 (mod 55) 5^7 (mod 55) 12^7 (mod 55) 12^7 (mod 55) 15^7 (mod 55).

ðŸŒ²c= 2 25 23 23 5. Swetha sends the ciphertext to Vijay.

ðŸ“Œ**Decryption:**

ðŸŒ²Vijay receives Swetha's ciphertext, 2 25 23 23 5.

ðŸŒ²Vijay calculates the plaintext, m, using the formula m = c^d (mod n).

ðŸŒ²In this case, m = 2^23 (mod 55) 25^23 (mod 55)23^23 (mod 55)23^23 (mod 55)5^23 (mod 55) = 8 5 12 12 15.

ðŸŒ²Vijay converts the number back to the message "HELLO" using the predetermined scheme.

ðŸ‘‰The link for the calculation is a calculator.

ðŸŽ¯**Below are the screenshots of the Python code used to create the RSA public, private, encryption, and decryption algorithms.**

ðŸ‘‰Please refer to the link to generate RSA keys using python RSA Keygen

ðŸŽ¯**The Public and Private key Generation**

ðŸŽ¯**Encryption Algorithm**

ðŸŽ¯**Decryption Algorithm**

ðŸŒ²**Strengths**

ðŸ‘‰When compared to symmetric encryption, there is no need to exchange the keys ahead of time.

ðŸ‘‰"Non-repudiation" is achieved because data cannot be changed during communication.

ðŸ‘‰It's a one-way function, so knowing one prime key won't get you the other primes.

ðŸŒ²**Weakness**

ðŸ‘‰The difficulty of generating keys.

ðŸ‘‰The RSA algorithm is relatively slow when compared to symmetric algorithms.

**Community and Social Footprints:**

### Did you find this article valuable?

Support **Cloudnloud Tech Community** by becoming a sponsor. Any amount is appreciated!