Take the 2-minute tour ×

Is possible to calculate average of three encrypted integer? No constrain on the method of encrypting. The point of this is just to hide the three numbers and find average.

share|improve this question
why not just store the average along with the encrypted numbers? If you're able to get an average from the 'encrypted' numbers, you haven't encrypted them well as they're still mathematically related. –  Cam Apr 4 '10 at 22:52
In my answer, I have assumed that you want the encrypted average as the outcome, not the unencrypted average. As incrediman already noted, being able to calculate the unencrypted average would leak information, which would be a very bad property for a cryptosystem. –  Wim Coenen Apr 4 '10 at 23:11

6 Answers 6

up vote 11 down vote accepted

What you seem to be looking for is called Homomorphic Encryption: an encryption scheme which allows you to perform operations on encrypted data, with the encrypted result as the outcome.

Such a scheme would allow you to give encrypted data to a 3rd party, which could then do computations on it for you without knowing what they were computing.

In your case, you need two operations: addition and division. Until recently, homomorphic encryption schemes typically supported only 1 operation. But in september 2009 IMB announced the first fully homomorphic cryptosystem. Other researches published another system soon after that.

These cryptosystems might be be able to do what you want, but it is all cutting edge computer science research.

share|improve this answer
Very interesting, thanks. –  Ben Challenor Apr 4 '10 at 23:14
This would work, if he doesn't mind that the result is still encrypted. If he wants the result to be decrypted, he might as well decrypt the input... –  Matti Virkkunen Apr 5 '10 at 9:24
What method would I use if I only want to "add" the numbers? No division. So what 1-operation-homomophic-encryption is best for adding encrypted numbers? –  heinob Jul 15 '13 at 7:38
@heinob: SB correct me if I'm wrong: if you had a large prime P, N numbers n(i), and N secret keys s(i) random in [0, P), then n(i)+s(i) mod P is encrypted. Then sum(n(i)+s(i)) mod P is sum(n(i)) mod P, encrypted with sum(s(i)) mod P. Does that sound right? –  Erhannis Nov 7 '14 at 20:20
Also, if modular division is a thing that makes sense here, that COULD work? I'd need to think about it more. –  Erhannis Nov 7 '14 at 20:23

Decrypt the numbers, then calculate their average.

share|improve this answer
I don't think that was the point of the question. I'm pretty sure the OP wants to compute the average without disclosing the individual numbers (even to the CPU computing the average). –  Marcelo Cantos Apr 4 '10 at 22:47
It might not be the point but, seriously, how else could it be sensibly done? –  David Thomas Apr 4 '10 at 22:53
That, exactly, is my point. –  Matti Virkkunen Apr 4 '10 at 23:08
There has been research done into encrypted computation, whereby the hardware doing the computing is unable to discover the inputs or the outputs. So the question isn't as silly as it sounds. –  Marcelo Cantos Apr 4 '10 at 23:22

I don't see any simple ways to do what you ask, apart from decrypting the numbers first.

Taking the average (or the "arithmetic mean") requires adding the numbers. Now if you wanted to multiply the numbers, then you could do that neatly with RSA encryption. If p is the plaintext, c is the ciphertext, and e is the encryption key, then in RSA, c = p^e. If you have 3 separate integers, p1, p2, p3, and the product is pp then

 pp^e = (p1 * p2 * p3)^e = p1^e * p2^e * p3^3 = c1 * c2 * c3 = cp

That is, you can either multiply the three plaintext integers together and then encrypt, or you can just multiply the three ciphertexts together, and get the same answer. This would get you some way towards the "geometric mean", where you multiply all the numbers together, and then take the cube-root (or nth root for n numbers). Unfortunately, calculating a cube root in modular arithmetic is non-trivial.

share|improve this answer

With ideal encryption methods: No.

With most real-world encryption methods: No.

With some stupidly simple to undo obfuscation method especially designed to allow averaging: Yes.

Calling the latter method "encryption" really would be using the wrong term.

If you could calculate the average of encrypted numbers without decrypting them, that would make decrypting the original numbers quite a lot easier, so I would be very surprised if this works with any serious encryption algorithm.

share|improve this answer

In general three encrypted numbers shouldn't maintain the same order if encrypted, so I'm pretty sure you have to decrypt them and calculate the avarage.

share|improve this answer

If, and only if, the method of encryption is a one-to-one mathematical function, then it is possible to do so while the numbers are encrypted.

For example, if my very unsecure method of encryption is to multiply every number of 2, then I would do the following:

function encrypt($number){
    return $number*2;

$a=encrypt(3); // a= 9
$b=encrypt(5); // b= 15
$c=encrypt(6); // c= 18

$average = ($a+$b+$c)/6; // We divide by 6 because first we divide by 3 to get the average, then by 2 to do the decryption. The method will vary based on the mathematical function.

The only other possibility is to decrypt the numbers first.

share|improve this answer

Your Answer


