ElGamal cipher decryption (reposted not from guest account) My sincerest apologies for having to repost this but I can't edit or post a comment from the previous one I asked with a guest account.

I'm learning about the Diffie-Hellman and ElGamal ciphers, but I'm really struggling trying to decipher the exercise my lecturer has given me.

The information I've been given (all in decimals) is

g

p

a (Alice private key)

A (Alice public key)

B (Bob public key)

C (ciphertext)

I've tried calculating a shared secret S = B^a mod p then inversing it and multiplying that by C as my lecturer described in the lecture but it doesn't work. Is that wrong and if yes what am I supposed to do??

I used this tool to perform the inverse operation (inverseMod(a,b))
http://www.mobilefish.com/services/big_number_equation/big_number_equation.php
You need to further specify your question. The Diffie-Hellmann Key Exchange Protocol is used to establish a secret key over a public channel. After the protocol run, both Alice and Bob have the same key $k_{ab}=A^b=B^a=g^{ab}$.

The El-Gamal system is based on asymmetric cryptography and therefore public keys and secret keys are required. Since the El-Gamal ciphertext consists of two parts $c=(c_1,c_2)$ your description of the decryption function seems to be mixed up. Have a look at the decryption formula of El-Gamal and try to calculate it step by step to understand how the cipher works.