LIVE NEWSROOM · --:-- · May 15, 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

    YARA-X 1.16.0: Faster Scans, Panic Fixes, and Neovim LSP Support YARA-X 1.16.0 ships with performance improvements across 10 PRs, constant folding for bitwise ops, configurable mat… Instructure Removed from ShinyHunters' Leak Site as Canvas Breach Deadline Passes Instructure was quietly removed from ShinyHunters' extortion site after the May 12, 2026 deadline — no data dump, n… Costa Rica Joins Have I Been Pwned as the 42nd Government Costa Rica's CSIRT gains free access to Have I Been Pwned's government domain monitoring service, becoming the 42nd… LummaC2 Infostealer Targets US Critical Infrastructure: CISA-FBI Advisory AA25-141B and DOJ Domain Seizures CISA and FBI advisory AA25-141B details LummaC2 MaaS infostealer TTPs targeting critical infrastructure. DOJ seized… MacSync Stealer: Hackers Abuse Google Ads and Claude.ai Chats to Push Mac Malware Russian-speaking attackers combine Google Ads and Claude.ai shared chats in a ClickFix campaign deploying MacSync S… JDownloader Site Hacked, Installers Swapped with Python RAT Malware JDownloader's website was hacked May 6–7, 2026, replacing Windows and Linux installers with a Python-based RAT. Use… Operation HookedWing: 4-Year Phishing Campaign Hits 500+ Organizations Across Aviation, Energy, and Logistics Operation HookedWing has stolen credentials from 500+ organizations in aviation, energy, logistics, and critical in… Twelve Critical vm2 Node.js Vulnerabilities Enable Sandbox Escape and Arbitrary Code Execution A dozen CVEs in the vm2 Node.js sandbox library — including CVSS 10.0 flaws — allow sandbox escape and RCE. Update …
    Scroll to Top