# Making Pascal Paillier' output absolute

Can we make subtraction result of cipher texts encrypted by Pascal Paillier absolute. Just like we use method Math.abs() in Java ? For example, if we subtract 0 from 1: 1-0 = 1, it is positive but 0-1 = -1. My requirement is that this subtraction should always be positive like:

   1 - 0 = 1
0 - 1 = 1


Is there anyway i can achieve it please?

• Technically, $-1$ is equivalent to a positive number in the Paillier group, but I am assuming that is not what you are looking for. – mikeazo Nov 2 '15 at 18:13
• @mikeazo you mean if i perform this operation: (1-0) + (0-1) + (1-0) then output will be 3 instead of 1 ? – Umer Nov 3 '15 at 6:46
• No, you would get 1. – mikeazo Nov 3 '15 at 13:04
• yes. But I want to get 3. – Umer Nov 3 '15 at 16:23
• If you know when to expect a negative number, you can multiply by -1, otherwise it is impossible. – mikeazo Nov 3 '15 at 16:41

Here's why: The $|a - b|$ operation is effectively an $XOR$; if the ciphertexts $a, b$ are known to be either encrypted $0$ or $1$ values, then the result will be a 1 if they differ, and 0 if they are the same.
In addition with a bit more work, we can compute an $AND$. To do this, we could first compute $a + b - |a - b|$. This value will be an encrypted 2 if $a, b$ are both 1, and 0 if either is a 0. Then, multiplying this value by the constant $(n+1)/2$ (which can be done in $O(\log n)$ homomorphic additions) will give us an encrypted 1 if both $a, b$ are 1, 0 otherwise (or, on other words, an $AND$ operation).
The combination of the $AND$ and $XOR$ operations are complete; that is, any function (computable in bounded time) can be implemented by a sufficient number of them.