LIVE NEWSROOM · --:-- · May 30, 2026
A LIBRARY FOR SECURITY RESEARCHERS

ElGamal Cryptosystem

Post on X LinkedIn
ElGamal Cryptosystem

Hello, 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.

encryption technique elgamal

// 01 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.

// 02 Working of ElGamal Cryptosystem

Here we explain the working of this algorithm: –

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

// 03 Steps of ElGamal

  1. Key generation process
  2. Encryption process
  3. Decryption process

Key Generation

  1. Select a large prime number (P)
  2. Select decryption/private key (D)
  3. Encryption public key (E1)
  4. E2 = E1D mod P
  5. Public keys are E1, E2, and P
  6. The private key is D
ElGamal Cryptosystem

Encryption

  1. Assume a random integer (R)
  2. C1 = E1R mod P
  3. C2 = (PT * E1R) mod P
  4. CT = ( C1,C2)

Decryption

PT = [C2 * (C1 ^ D)-1] mod P

// 04 Example

Lets take, 

P = 10
D = 2
E1 = 3

Therefore,
 E2 = E1D mod P  
      = 32 mod 10
      = 9 mod 10
      = 9
Now, public keys are (E1, E2, P) i.e. (3, 9, 10)

Encryption

Lets take,
R = 1
PT = 4

therefore,
 
C1 = E1R mod P
      = 31 mod 10
      = 3 mod 10
      = 3

C2 = (PT * E2R) mod P
      = (4 * 91) mod 10
      = 36 mod 10 
      = 6

Now, cipher texts are (C1, C2) i.e. (3, 6)

Decryption

PT = [CT * (C1D)-1] mod P
      = [6 * (32)-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

// 05 Uses of ElGamal Cryptosystem

  1. Encrypting and decrypting messages.
  2. Use in Digital signatures.
  3. Used for Key exchange.
  4. Use for Network Security
  5. Uses for Cryptographic protocols

// 06 Advantages and Disadvantages of ElGamal Cryptosystem

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

Advantages

  1. It is more secure than the original Diffie-Hellman key exchange because it uses larger prime numbers and a random number generator.
  2. 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.
  3. The ElGamal algorithm is widely used and supported by a number of cryptographic protocols and applications.

Disadvantages

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

    TE
    Team Ciphers Security

    Independent cybersecurity desk publishing daily threat intel and research since 2021. Practitioners writing for analysts, defenders, and learners. About us →

    Previous Introduction to PHP Programming language Next What is Information Gathering

    Latest News

    How to Automate Compliance Evidence Collection (Drata & Vanta 2026) Learn how to automate compliance evidence collection in 2026 using Drata or Vanta — step-by-step setup for AWS, Git… Best CNAPP Platforms 2026: Multi-Cloud Enterprise Buyer's Guide Best CNAPP platforms 2026: Wiz, Prisma Cloud, CrowdStrike, Orca, Lacework, Sysdig, Aqua, and Defender ranked for mu… Druva vs Rubrik vs Cohesity: Immutable Backup for Ransomware Recovery 2026 Compare Druva vs Rubrik vs Cohesity immutable backup for ransomware recovery 2026: architecture, RTO/RPO, pricing, … Drata vs Vanta vs Tugboat Logic: Compliance Automation Comparison 2026 Compare Drata vs Vanta vs Tugboat Logic on pricing, framework breadth, integrations, and time to audit-ready for SO… JINX-0164 Targets Crypto Firms with macOS Malware and CI/CD Hijacking JINX-0164 targets crypto firms with AUDIOFIX macOS malware via fake LinkedIn recruiters and CI/CD supply chain pois… CSPM vs CWPP: Choosing the Right Cloud Security Tool in 2026 CSPM vs CWPP cloud security 2026 guide: compare Wiz, Prisma Cloud, Lacework, and Defender for Cloud with a decision… FBI USB Insider Threat Alert: DLP Policy and Detection Controls FBI USB insider threat alert: Silent Ransom Group sends operatives to insert USB drives at law firms. Enterprise DL… Best Vulnerability Management Tools for Enterprise Security Teams in 2026 Evaluate the best vulnerability management tools enterprise 2026: Tenable, Qualys, Rapid7, Wiz, and Falcon Spotligh…
    Scroll to Top
    Ad