Table of Contents

ToggleHello, guys :), Varsha here, and in this article, we will discuss the encryption algorithm known as ElGamal encryption or ElGamal algorithm. In this article, we will discuss the working of the ElGamal algorithm with examples.

After reading this article you will be able to understand the working and importance of this algorithm as well as you can also do the mathematical calculations of this algorithm.

## ElGamal Cryptosystem

ElGamal is a public-key encryption algorithm that uses the Diffie-Hellman key exchange to produce a shared secret key. The algorithm has three components: a random number generator, a function to compute the product of two large prime numbers, and a function to compute the modular inverse of a number.

The ElGamal cryptosystem is considered to be more secure than the original Diffie-Hellman key exchange because it uses larger prime numbers and a random number generator, making it more difficult for an attacker to break the system.

## Working of ElGamal Cryptosystem

Here we explain the working of this algorithm: –

- Alice (A) and Bob(B) agree to use ElGamal to communicate securely.
- Alice generates two large prime numbers, p and q, and a random number, g. She sends p, q, and g to Bob.
- Bob generates a random number, x, and computes y = g^x mod p. He sends y to Alice.
- A generates a random number, a, and computes b = g^a mod p. She sends b to Bob.
- B computes the shared secret key, k = b^x mod p.
- A computes the shared secret key, k = y^a mod p.
- Both users now have the same shared secret key, k, which they can use to encrypt and decrypt messages sent between them.

## Steps of ElGamal

- Key generation process
- Encryption process
- Decryption process

### Key Generation

- Select a large prime number (P)
- Select decryption/private key (D)
- Encryption public key (E
_{1}) - E
_{2}= E_{1}^{D}mod P - Public keys are E
_{1}, E_{2}, and P - The private key is D

### Encryption

- Assume a random integer (R)
- C
_{1}= E_{1}^{R}mod P - C
_{2}= (PT * E_{1}^{R}) mod P - CT = ( C
_{1},C_{2})

### Decryption

PT = [C_{2} * (C_{1} ^ D)^{-1}] mod P

## Example

```
Lets take,
P = 10
D = 2
E
```_{1} = 3
Therefore,
E_{2} = E_{1}^{D} mod P
= 3^{2} mod 10
= 9 mod 10
= 9
Now, public keys are (E_{1}, E_{2}, P) i.e. (3, 9, 10)
**Encryption**
Lets take,
R = 1
PT = 4
therefore,
C_{1} = E_{1}^{R} mod P
= 3^{1} mod 10
= 3 mod 10
= 3
C_{2} = (PT * E_{2}^{R}) mod P
= (4 * 9^{1}) mod 10
= 36 mod 10
= 6
Now, cipher texts are (C_{1}, C_{2}) i.e. (3, 6)
**Decryption**
PT = [CT * (C_{1}^{D})^{-1}] mod P
= [6 * (3^{2})^{-1}] mod 10
= [6 * 9^{-1}] mod 10 ------------> 1
To find 9^{-1} , we havte to prove that,
9 *x mod 10 = 1
9 * 9 mod 10 = 1
81 mod 10 = 1
1 = 1 (i.e. x = 9)
Hence proved
Therefore, from 1 we get
PT = [6 * 9] mod 10
= [6 * 9] mod 10
= 54 mod 10
= 4

## Uses of ElGamal Cryptosystem

- Encrypting and decrypting messages.
- Use in Digital signatures.
- Used for Key exchange.
- Use for Network Security
- Uses for Cryptographic protocols

## Advantages and Disadvantages of ElGamal Cryptosystem

The ElGamal algorithm has several advantages and disadvantages, including the following:

### Advantages

- It is more secure than the original Diffie-Hellman key exchange because it uses larger prime numbers and a random number generator.
- The ElGamal algorithm allows for the creation of digital signatures, which can be used to verify the authenticity and integrity of a message or document.
- The ElGamal algorithm is widely used and supported by a number of cryptographic protocols and applications.

### Disadvantages

- It is slower and more computationally intensive than some other public-key encryption algorithms.
- Its security relies on the difficulty of factoring large prime numbers, which is considered to be a potential weakness.
- It is not suitable for encrypting large amounts of data, as the key size increases with the amount of data being encrypted.

**If you have any queries regarding the above content, or you want to update anything in the content, then contact us with your queries. You can directly post your question in the group.**

**Connect with us on these platforms**