views:

175

answers:

6

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.

+4  A: 

Decrypt the numbers, then calculate their average.

Matti Virkkunen
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
It might not be the *point* but, seriously, how else could it be sensibly done?
David Thomas
That, exactly, is my point.
Matti Virkkunen
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
+1  A: 

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.

ndim
A: 

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.

klez
+2  A: 

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.

John
A: 

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.

waiwai933
+9  A: 

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. I've often wondered whether something like this would be possible to distribute the load of a MMORPG to the players without giving them the ability to tamper with the game.

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.

Wim Coenen
Very interesting, thanks.
Ben Challenor
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