We look more at cryptography, examining a special-purpose protocol for finding the average without revealing numbers.
To convince Alice he's truly Bob, Bob uses a signature.
Bob has two keys, one published, one kept private.
Messages sent encrypted by the private key make sense only with the published key, but encryption with the private key can't be imitated.
So Eve can't masquerade as Bob!
Alice, Bob, Krunch, and Spot just got their test grades.
Alice 95 Bob 88 Spot 50 Krunch 82
They want to know their average score, but nobody wants to reveal their grades.
What can they do?
We write x mod N to denote the remainder of x divided by N.
For addition, this gives ``wrap-around'' behavior. For 0 <= x < N, 0 <= y < N,
x + y if x + y < N (x + y) mod N = { x + y - N otherwiseNotice that modulo addition is commutative and associative.
We take N to be 401, because the total of the four scores will be less than 401.
All behave the same.
Let's look at an example.
sends to whom who Alice Bob Spot Krunch total Alice 135 240 301 221 = 95 = Alice's score Bob 285 363 109 133 = 88 = Alice's score Spot 135 300 334 83 = 50 = Spot's score Krunch 132 5 230 116 = 82 = Krunch's score --- --- --- --- --- total 286 106 172 152 = 315
Because, as we observed, addition is commutative and associative, we can find the sum of all the entries either by summing the rows first (and getting the actual scores) and then totaling these sums, or by summing the columns first and then totaling these sums. The first is the total of the scores; the second is what the algorithm does. But they're both the total of everything in the array, so the answer is correct.