ElGamal Encryption Calculator
Enter a prime p, generator g, private key x, ephemeral key k, and message m.
Result
How it is calculated
All arithmetic is modular, using fast exponentiation. With prime p, generator g, private key x, ephemeral key k and message m: y = gx mod p, c1 = gk mod p, s = yk mod p, c2 = m × s mod p. The pair (c1, c2) is the ciphertext, y is the public key and s is the shared secret. Inputs are cut to whole numbers. The tool needs p of at least 3, g of at least 2, x and k of at least 1, and 0 ≤ m < p; p up to about 3.03 billion works. It does not check that p is prime or that g is a generator, so that is your responsibility.
Worked example
Take p = 23, g = 5, x = 6, k = 3, m = 10. Public key: 56 mod 23 = 8. First part: c1 = 53 mod 23 = 125 mod 23 = 10. Shared secret: s = 83 mod 23 = 512 mod 23 = 6. Second part: c2 = 10 × 6 mod 23 = 60 mod 23 = 14. The ciphertext is (10, 14), the public key is 8, and the shared secret is 6.
Common mistakes
- Choosing a message m equal to or larger than p. The message must be a whole number below p, otherwise there is no result; split longer data into blocks.
- Using a non-prime p such as 4 or 24. The tool still returns numbers, but they are not a secure or properly decryptable ElGamal setup.
- Setting x or k to 0. Both must be at least 1, so the tool gives nothing for 0.
- Typing a decimal message such as 10.7. It is silently cut to 10, which changes what you encrypt.
- Reusing the same k for two messages. Real ElGamal needs a fresh k each time; this tool only shows one run.
About this calculator
The ElGamal cryptosystem, published by Taher Elgamal in 1985, is a public-key encryption scheme whose security rests on the discrete logarithm problem in a finite cyclic group — given a prime p and generator g, it's computationally hard to recover x from y = g^x mod p. Key generation picks a private key x and publishes y = g^x mod p as the public key; encryption then draws a fresh random ephemeral key k for every message and produces a ciphertext pair (c₁, c₂) = (g^k mod p, m·y^k mod p), so the same plaintext never encrypts to the same ciphertext twice.
This calculator walks through that math step by step: enter a small prime p, generator g, private key x, ephemeral key k, and an integer message m, and it derives the public key and the resulting ciphertext pair exactly as the algorithm would. Cryptography students, computer science instructors, and security engineers use toy examples like this to build intuition for asymmetric encryption and for the discrete-log basis that also underlies Diffie-Hellman key exchange and the DSA signature scheme — real deployments use primes hundreds of digits long, far beyond hand or calculator arithmetic.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
To check the output by hand as the receiver would, raise c1 to the private key modulo p. With the default values, 10 to the power 6 mod 23 is 6, which matches the shared secret shown, and multiplying c2 by the inverse of 6 mod 23 returns the message 10. Treat all of this as a classroom toy; never encrypt real data with small numbers. Which step do you find hardest?