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:
- Privately available $\EA(x)$ and $\EB(x)$, which encrypt, and
- 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$.