Pyfhel icon indicating copy to clipboard operation
Pyfhel copied to clipboard

How to find the Hamming distance of two vectors in ciphertext domain?

Open zxcCEn opened this issue 3 years ago • 1 comments

Hello, I want to know what the specific form of ciphertext is. Can we calculate the number of non-zero elements in the ciphertext vector after subtracting the two encrypted vectors so as to calculate the Hamming distance? Or can we directly use the method in NUMpy to solve the Hamming distance

zxcCEn avatar Jul 24 '22 07:07 zxcCEn

Finding out if an element is non-zero (i.e. computing f(x) = (x != 0)) can be tricky under encryption. If the vector elements were already binary, then it's very easy, but otherwise, it's definitively an "advanced" thing to do.

AlexanderViand avatar Aug 05 '22 09:08 AlexanderViand

Demo_8_HammingDist.py shows how to calculate the hamming distance in a well detailed script. As mentioned by @AlexanderViand , the main requirement is to encode vectors with binary values {0,1}*, in which case you can resort to arithmetic scalar product since XOR(a, b) = a + b - a*b.

Closing with this working example!

ibarrond avatar Oct 04 '22 21:10 ibarrond