-1
$\begingroup$

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
95 => AD48FF99415B2F007DC35B7EB553FD1EB35EBFA2F2F308ACD9488EEB86F71FA8

AD48FF99415B2F007DC35B7EB553FD1EB35EBFA2F2F308ACD9488EEB86F71FA8 - 785F3EC7EB32F30B90CD0FCF3657D388B5FF4297F2F9716FF66E9B69C05DDD09 = 73

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.

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

If you want to encrypt two numbers in such a way that the arithmetic difference can still be obtained from the encrypted values then all you need to do is encrypt one of the numbers and send it together with the difference between the two numbers:

$$[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.

$\endgroup$
  • $\begingroup$ My problem is that I want to create something like this: 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. $\endgroup$ – Kastuto Jun 7 '18 at 11:15
  • $\begingroup$ So if a person can compute their own value's code and then calculate the difference to all other code then they can workout all of the other values. Is this what you mean? $\endgroup$ – Jackoson Jun 7 '18 at 23:00
  • $\begingroup$ Not exactly, their values are encrypted by a service. $\endgroup$ – Kastuto Jun 8 '18 at 13:10
  • $\begingroup$ You got a point. I was exploring homomorphic encryption, had also something working, but I would be better to have homomorphic using a key/pair to store your own values so your privacy would be protected. My problem is still that I want to log when a user is approaching a value (immagine a turn based game where following certain rules the higher value wins) $\endgroup$ – Kastuto Jun 8 '18 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.