Homomorphic Encryption With ElGamal: Multiply/Divide
There are some encryption methods which allow us to process encrypted values. In this way we can process using certain mathematical operations on cipher values, and end up with the result when we decrypt. For example, if we encrypt a value of 4 and a value of 3 with a public key we get:
Epub(4), Epub(3)
If we now multiply these values we get:
Res=Epub(4)xEpub(3)
If we now decrypt the result (Res) with the private key, and the answer is 12, we have performed a multiplication on the encrypted values. RSA is one method that we can perform a multiplication and division — and is defined as a partial homomorphic encryption (PHE) method. Another method we can use to multiply and divide is ElGamal. If you are interested, here is the method [here]:
Basically, we compute the cipher values (a,b) for both integer values, and then multiply the a values and multiply the b values. The decryption process is then just the same as with a single value. The Python code for this is [here]:
from Crypto.Util.number import *
from Crypto import Random
import Crypto
import random
import…