Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xor output is incorrect #48

Open
keito89 opened this issue Feb 12, 2025 · 0 comments
Open

Xor output is incorrect #48

keito89 opened this issue Feb 12, 2025 · 0 comments

Comments

@keito89
Copy link

keito89 commented Feb 12, 2025

I am not much familiar with MOTION so facing lots of issues. I want to Xor two inputs but the results generated is 0, while it should be 102. may be i am not retrieving result in a correct manner. Can any body guide me whats wrong in the code.

CODE:

// abbreviate namespace
namespace mo = encrypto::motion;
using namespace std;

void EvaluateProtocol(encrypto::motion::PartyPointer& party) {

    // Define 32-bit values representing shares of 1 and 0
std::uint32_t value1 = 0b10101010;  // Example binary value (170 in decimal)
std::uint32_t value2 = 0b11001100;  // Example binary value (204 in decimal)


std::cout << "Value1: " << value1 << " | Value2: " << value2 << std::endl;

// Create Boolean GMW shares
mo::ShareWrapper share1 = party->In<mo::MpcProtocol::kBooleanGmw>(mo::ToInput(value1), 0);
mo::ShareWrapper share2 = party->In<mo::MpcProtocol::kBooleanGmw>(mo::ToInput(value2), 0);

// Use Boolean GMW's built-in XOR operation
mo::ShareWrapper xor_result = share1 ^ share2;


// Retrieve the output
xor_result = xor_result.Out();

// Run the protocol
party->Run();
party->Finish();

// Extract the Boolean GMW result
std::vector<encrypto::motion::BitVector<>> reconstructed_value =
    xor_result.As<std::vector<encrypto::motion::BitVector<>>>();

// Fix: Convert BitVector<> to Integer manually
std::uint32_t final_value = 0;
const auto& bit_vector_data = reconstructed_value[0].GetData();  // Get raw bits
cout << "bit_vector_data size" << reconstructed_value[0].GetData().size() << endl;

// Convert bit vector data into an integer
for (std::size_t i = 0; i < bit_vector_data.size(); ++i) {
    final_value |= static_cast<std::uint32_t>(bit_vector_data[i]) << i;
}

std::cout << "XOR Result: " << final_value << std::endl;

}

Value1: 170 | Value2: 204
bit_vector_data size1
XOR Result: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant