Closed winnnnnny closed 1 year ago
You get the or of a
and b
by using |
as mentioned in #36. If you replace the line where you assign bitor
by:
bitor = a | b
you get the expected result because '|` is overloaded for secure integers.
Here, a
and b
are not required to be of the secure integer type mpc.SecInt(1)
with bit length exactly 1, but can be of type mpc.SecInt(16)
for instance as long as the values of a
and b
are 0 or 1 (bit values). Such a
and b
may arise from secure comparisons between secure integers, e.g., a = r < s
and b = r < t
, or from secure bit decompositions.
Thank you for your suggestion! Now I can use a | b to implement bitwise or successfully.
Sorry for disturbing you again. I cannot implement bitwise not successfully. From the document, I should use mpc.convert, but the result is unexpected. Here is the code.
from mpyc.runtime import mpc
async def main():
secint = mpc.SecInt(1)
a = secint(1)
b = secint(0)
result = mpc.invert(a & b)
print("result:", await mpc.output(result))
mpc.run(main())
The result is shown below.
2023-05-30 19:52:39,052 Install package numpy for more functionality.
2023-05-30 19:52:39,052 Install package gmpy2 for better performance.
result: -1
I expect the result to be 1 from not(0), but the result is -1. How should I implement not?
Use ~
which is also overloaded for secure integers:
result = ~(a & b)
Thank you for your suggestion!
Hello, sorry for disturbing you. I want to conduct a bitwise on two secure integers. I observed that the mpc._or is limited to 1-bit only, so I try to use 1-bit secure integer but the result was still unexpected. I also tried the methods mentioned in #36, it works but may be a bit complex. The coding is shown below.
The result is shown below.
a
andb
are two 1-bit secure integers, but the result is still unexpected. Does it mean I have to implement the or like #36?