TITLE: Calculate unique Integer representing a pair of integers
QUESTION [5 upvotes]: I have a pair of positive integers $(x, y)$, with $(x, y)$ being different from $(y, x)$, and I'd like to calculate an integer "key" representing them in order that for a unique $(x, y)$ there is an unique key and no other pair $(w, z)$ could generate the same key.
I don't mind if we can/can't guess the pair values based on the key.
The key must be < 2,147,483,647 and the value of $x$ and $y$ as high as possible.
Any solution ?

REPLY [3 votes]: Another unique key for non-negative integer pairs is
$$\mathrm{key}(x,y)=\max(x,y)^2+\max(y,2y-x)$$
This covers squares first, so should meet your conditions as well as not being limited to a given argument maximum. That is, if $\max(x,y)\lt2^n$, then $\mathrm{key}(x,y)\lt2^{2n}$.
$\hspace{4cm}$