# 2 Person Same Number Verification

Alice and Beth both receive a random integer from 1 through 10, inclusive. They only know the number that they are given.

The two of them want to come up with an algorithm to check that their sampled numbers are indeed different, but ensure that they reveal no information about their individual numbers (apart from the fact that they are different!).

Either find an algorithm that does such, or prove that no such algorithm exists.

• is there unlimited guesses? is this supposed to be efficient? can I simply make them each guess Oct 24 '19 at 13:40
• until comopletion? Oct 24 '19 at 13:45
• @JasonV Guess what exactly? They don't want to know each others numbers. They want to verify they are distinct. Oct 24 '19 at 13:46
• There is a lot of in depth discussion on Crypto SE here, and it seems to be a rather difficult problem, at least if you want to make sure that neither Alice nor Beth can cheat. Oct 24 '19 at 14:36
• And more generally, what techniques are allowed? Should this be thought of in the abstract cryptographic sense, like "Alice and Beth can send each other messages, but that's all"?
– Deusovi
Oct 24 '19 at 20:41

Any commutative hash function will do.  Using RSA makes this relatively easy, I think.

So Alice and Beth both establish their secret primes, and, in a twist, keep everything secret.  $$% Make EA, EB, DA and DB look like functions; i.e., *not* italic: \def\EA{\operatorname{EA}} \def\EB{\operatorname{EB}} \def\DA{\operatorname{DA}} \def\DB{\operatorname{DB}}$$ Then they have:

1. Privately available $$\EA(x)$$ and $$\EB(x)$$, which encrypt, and
2. Privately available $$\DA(x)$$ and $$\DB(x)$$, which decrypt (not used).

So $$f_1(f_2(x))=f_2(f_1(x))$$, where $$f_1$$ and $$f_2$$ are any two of $$\EA$$, $$\EB$$, $$\DA$$ and $$\DB$$.

Now suppose Alice's number is $$a$$ and Beth's is $$b$$.  Then Alice publishes $$\EA(a)$$ and Beth uses that to publish $$\EB(\EA(a))$$.

Similarly, Beth publishes $$\EB(b)$$ and Alice uses that to publish $$\EA(\EB(b))$$.

These two are equal if and only if $$a=b$$, but no information leaks if they are different.

A simple hash that could be used is to pick a secret number $$y$$ and share a number $$z$$ (e.g., 1000000) and then work out $$2^{a+y} \mod z$$.

• This works, at least if Alice and Beth trust each other to not lie. If there were an advantage to knowing that their numbers are the same while keeping the other in the dark about that fact, then all bets are off. Alice could publish EA(a) correctly, but lie when publishing EA(EB(b)) by giving a different result. Beth would think their numbers are different, but Alice could (assuming Beth did not also lie) still find out whether the numbers matched by checking the real value of EA(EB(b)). Of course, Beth would have an incentive to lie too, so the whole scheme then falls apart. Oct 24 '19 at 15:03
• I have to point out that there is no Bob in this puzzle. Oct 24 '19 at 19:56
• @SteveV Permutations generally do not commute, and you need commutativity for this method to work. I thought for a moment you could use bitwise XOR with a private key, but it really also needs to be a one-way function so that it cannot be undone, i.e. knowing one plaintext/encryption pair (e.g. EA(a) and EB(EA(a)) ) should not allow the decryption of another number (e.g. EB(b) ). Oct 24 '19 at 21:33
• @DrXorile Is that hash function commutative? Oct 25 '19 at 6:42
• @Spoonless That is why even though RSA is used, the (normally public) encryption keys are kept private as well. Oct 25 '19 at 14:38

There are 10 rooms labelled 1-10. Put Alice in her room, and ask Beth to go through the door with her number on it. When this is done, turn the lights back on - if the two girls are in the same room, they have the same number. If not, they don't, and no-one is any the wiser other than that.

• This seems along the lines of 'third party'--as coordinating this becomes difficult with just Alice and Beth, and as the number of rooms becomes large. Oct 24 '19 at 15:22
• @nahmid not really, they can coordinate everything by themselves (thinking cell phones here), so the room numbers act like a hash function that only reveals information when both secrets are equal.
– Bass
Oct 24 '19 at 15:59
• I see your point, thanks Oct 24 '19 at 16:02
• I can't tell if the question specify Alice and Beth are not supposed to reveal their number in case they are the same? If not this is a good way to test
– Alex
Oct 24 '19 at 21:06
• @Moo-Juice If Alice knows her own number and she knows that Beth has the same number, she will always know the number Beth has, because it is the same as her own. So any algorithm will indirectly reveal the other ones number, if they have the same number - by logical deduction. Oct 25 '19 at 13:45

Alice takes 1 cardboard box, 10 envelopes, 9 matching coins or disk, and 1 coin/disk of the same size/shape/weight, with a different colour or pattern. This difference may be disclosed in advance - see the final step.

Alice places 1 coin in each of the envelopes and seals them all (keeping track of the "different" coin) then stacks the envelopes inside the cardboard box, with the "different" coin at the position indicated by her number - i.e. on top for 1, at the bottom for 10, and so on. The cardboard box is used to prevent Beth from being able to observe the order that Alice stacks the envelopes in.

Beth and Alice then swap places. Beth retrieves the envelope that matches her number from the stack - the cardboard box again preventing Alice from observing which envelope is taken. The box is shaken vigorously to scramble the untaken envelopes, and returned to Alice.

Under observation of both, either Beth's envelope (if the difference is known) or all envelopes (in a random order) are opened. If Beth's coin is not the odd one out, they have different numbers.

(While Alice could mark the envelopes to learn about Beth's number, Beth can see the envelopes to certify that this has not happened. Similarly, Beth could open additional envelopes to find Alice's number - but Alice can certify whether or not the returned envelopes have been tampered with)

• Nicely done! I wasn't able to visualize how this process might work, but it's good that you could :)
– Avi
Oct 25 '19 at 13:16
• @Avi Essentially, I tried to deduce a method by which Alice could indicate True / False, for all 10 numbers, which would destroy the other 9 options when Beth selected any of them, while also preventing Alice from knowing which item was taken. Oct 25 '19 at 14:54
• (1) Upvoted because this takes the concept of JMP’s answer and makes it logistically practical and somewhat scalable (although it may be impractical for $N$ greater than, say, $100$).  (2) I don’t see why you need coins or disks.  ISTM that all you need is $N-1$ blank pieces of paper and one piece of paper that says “yes”.  It might be possible for Alice to cheat by making the blank sheets non-identical.  Allowing Beth to produce (and/or inspect) the $N$ pieces of paper may suffice as a countermeasure. … (Cont’d) Oct 26 '19 at 18:16
• (Cont’d) ... (3) I don’t see why you need the box — just have the participants turn their back when they are handling the envelopes. Oct 26 '19 at 18:16

Alice takes a basic calculator (a simple one that doesn't show history) and covers up the screen with something (paper, non-transparent tape, etc). Alice types in her number and hits the divide key. Beth takes the calculator, types in her number and hits the equals key. They take the cover off the screen and if the screen shows any number other than 1, they have different numbers.

• I like this, but they are supposed to reveal no information about their individual numbers. If the calculator shows anything else than 1 it could very well reveal their numbers. Oct 24 '19 at 17:40
• @Wolff With a trick we can get this to work? While reading the answer from the calculator, first cover it with a paper and slowly move the paper downward, to a point you see some pixels. You will be able to see if the answer has more than 1 digit. Secondly, while still covering the answer, only read the first rightmost digit. From these you can tell if the answer is not a '1' but unable to tell the answer. Much like when you play cards from casino. I mean this might not be an algorithm but kinda works
– Alex
Oct 24 '19 at 22:03
• @Alex, there might be a trick. But if Alice has 1 and Beth has 10 the calculator could show 0.1 so you'll have to move the paper until you see the period and then they both know what the other had. Oct 24 '19 at 22:36
• Most calculator have a "ans" key. So instead of a division, use a soustraction. then type "ans/ans". So if the numbers are the same it will show "ERROR" and if they are differents, it will show 1. This also work with calculators that show the calcul.
– GAB
Oct 25 '19 at 8:15
• @GAB even without an ans key, they could just type blind: zero divded by ( a - b ) and look at the result. If it shows 0 they had different number, if it shows ERROR they had the same Oct 25 '19 at 13:58

Possibly a modification of @JMP's answer:

Alice and Beth write a following Python script (or an equivalent in other language) and run it on a computer:


# getpass prompts the user to enter a string (a password) without echoing
from getpass import getpass
a = getpass("Alice: ")
b = getpass("Beth: ")
try:
print(int(a) != int(b))  # prints True if their numbers are different, False otherwise
except:
# to avoid echoing in case of something mistyped, e.g. '8a' instead of '8'
print("Non-number string entered")

Then Alice inputs her numbers, and then Beth inputs her one (of course, they do it while the other girl does not see the keyboard). By the output, they both can see the result (even not having to reveal their numbers to each other when they are the same (comment by @Alex to @JMP's answer) - but this requirement seems useless, since they obviously would know the numbers of each other if they know that the numbers are the same).

that this solution works with any range of possible numbers (e.g. if it would be 1 to 1 000 000 000, it's difficult to even build a billion rooms (and much more difficult is not to get lost inside them)).

• If Beth is a clever hacker, she can find the value of a in the program's memory. Oct 26 '19 at 16:39

Assuming Alice and Beth can be assigned the same number, then no such algorithm exists, since the algorithm would sometimes reveal that the numbers are not distinct, which means revealing their numbers to each other.

(If Alice and Beth cannot be assigned the same number, then that needs to be specified)

• From the question "but ensure that they reveal no information about their individual numbers (apart from the fact that they are different!)." - so the information different/same may be revealed (this is the goal of the algorithm) but nothing else. - So if they have the same number, the information can be revealed. Oct 25 '19 at 13:55

If you use truncating division, either $$\frac{a}{b}$$ or $$\frac{b}{a}$$ will be $$0$$, provided that $$a\neq{}b$$. Therefore, let Alice and Beth hand over their numbers to a trusted black box (which will never reveal their information), that will simply return to Alice and Beth the value $$\frac{a}{b}\cdot{}\frac{b}{a}$$. If the values are the same, this will return $$1$$, otherwise $$0$$. Establishing a trusted black box is the hard part here.

• You can't use a third party, otherwise the problem becomes trivial. Just have A and B tell their numbers to the third party individually and let the third party tell them whether they are different or not... Oct 24 '19 at 14:30
• @AlexanderGeldhof Good point. Looks like this won't work, then :(
– Avi
Oct 24 '19 at 14:31
• @avi See my answer, in which the "trusted black box" is literally a cardboard box, used to transmit only the information of "same" or "different" Oct 25 '19 at 13:11

Write a computer program that takes 2 input parameters one after another (performs clear screen after each input given) and then returns a boolean true or false depending on the result of the (a==b) operation.

An additional buffer flush can be performed once the result is displayed, to prevent either person from reading the given inputs (assuming they are adept enough to retrieve data from the buffer).

Sure, the computer acts as a 3rd party here but it cannot disclose information if you close out loopholes.

If the result of (a==b) is True, the numbers match. If the result is False, they don't.

Open 2 minecraft clients. In the seed section of the map input Alice's and Berth's numbers.

If the maps have the same structure then they have the same number.

• Problem: After doing this, Alice can open another minecraft client, and try entering keys until she finds one with the same structure as the one from Beth's key. Oct 25 '19 at 12:30
• Right, but then any algorithm with endless time can be broken right? Also I think this same answer can be applied to the polarisation algorithm I read below Oct 25 '19 at 15:31

Both define a conversion from their numbers to a rotation of a polarisation filter.

Then they adjust a polarisation filter to that rotation, so that if their numbers are equal, the direction of polarisation of both filters is the same.

Now Alice sends a string of random 0/1 as polarised light (single quantums). When sending a 1 the polarised light has to be aligned with her filter, when sending a 0 it has to be orthogonal. Only if Bobs filter is aligned exactly as Alices, he will receive the exact same string when looking through his filter, seeing 1 as light on and 0 as light off. If it is misaligned, he will receive a randomized string. Now Bob sends a shifted sequence of the same string. If Alice receives, what she sent, their numbers are equal. Now they can repeat the same into the other direction, so Bob knows the result, too.

This is based on some methods of post quantum key exchange I've read about and should guarantee, that no Information leaks and it is at least close to "just sending messages" and doesn't require a 3rd party.

• Wouldn't a misaligned filter result in results which correlate imperfectly to the original data, not independently random results? So if Alice sees that 80% of the bits returned match what she sent, she can calculate the approximate angle between the two polarizers. Oct 26 '19 at 16:45
• @aschepler Yes, you are right - hashing the message should fix it though. Oct 28 '19 at 7:02
• Hashing at what point? I'm not seeing how that could prevent a calculation of angle. Oct 28 '19 at 12:34
• @aschepler the returning message. Alice sends 10011001 - Bob receives 10111001, now he hashes that and sends back the hash. Alice can compare the hash result of her sent message with what Bob got out of it. If it is a mismatch, she wouldn't know, how much of difference there is. Oct 29 '19 at 12:49

Based on the answer by @rfajardo and the comment by @Falco:

1. Take a calculator and cover the screen
2. Alice enters her number and hits -
3. Beth enters her number and hits = and 1/x
4. Alice hits / or * followed by any number except 0 and then = , making sure that Beth does not see the input
5. Beth does the same, without Alice seeing it
6. Uncover the screen

If the screen shows Error (on my mobile phone) or 0 (on my RPN calculator), the numbers were equal. Any other result means that the numbers were different, but they can not tell which numbers it were.

• Even easier by just entering 0 / ( a - b ) Oct 25 '19 at 14:43
• @Falco that is right Oct 25 '19 at 14:45

Request to show up at a designated place at the time of your number. Leave at 5 minutes past your number's time and only arrive within 5 minutes before. If they both show up, they have the same number. This assumes both parties are in good faith but all of the algorithms inherently assume that as well. (This is clearly not the most time efficient way, but it was fun to imagine)