Encrypt 2 numbers preserving arithmetic correlation

I want to encrypt 2 numbers using a public key and have the reader know the correlation between those 2 numbers. I can also share the public key. Example:

22 => 785F3EC7EB32F30B90CD0FCF3657D388B5FF4297F2F9716FF66E9B69C05DDD09



Is there any hashing or encryption algorithm that give me the chance to do something like that?

Would be ok also a one way hash.

Edit: I'll try to be clear here You have a table (list) of those hashes and you have to be able to calculate the difference without knowing the actual numbers. Also you have to be able to hash your number. It's made so that you never reveal your number but you can understand how big is your number compared to one on the list. So maybe a hashing function would be better than encrypt using keys.

• I added more details to increase readability. – Kastuto Jun 7 '18 at 11:14
• Don't bother. If you have a known plaintext ciphertext pair then you can compute any plaintext from ciphertext. P' = P + (C' - C) – Future Security Jun 7 '18 at 15:12
• Please note that if you can compute the distance to any encrypted entry, an attacker can use binary search to recover that number. – SEJPM Jun 7 '18 at 18:28
• Also it appears that you may be looking for order-preserving encryption? – SEJPM Jun 7 '18 at 18:29
• As an aside, this reminds me of the millionaire's problem, that is solved by multiparty communication. – Jackoson Jun 8 '18 at 22:04

$$[x, y] \ \to \ [\textrm{enc}(x), y-x]$$
Without the decryption key, nobody will be able to find the value of $x$ or $y$, but anyone will be able to see the difference between these numbers.
You will probably also want to use probabilistic encryption (e.g., RSA encryption with randomized padding) to ensure that the same number $x$ never results in the same encrypted value.