ceremonyclient/emp-tool/test/bit.cpp
Cassandra Heart dbd95bd9e9
v2.1.0 (#439)
* v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete

* 2.1.0 main node rollup
2025-09-30 02:48:15 -05:00

66 lines
1.5 KiB
C++

#include "emp-tool/emp-tool.h"
#include <iostream>
using namespace std;
using namespace emp;
void test_bit() {
bool b[] = {true, false};
int p[] = {PUBLIC, ALICE, BOB};
for(int i = 0; i < 2; ++i)
for(int j = 0; j < 3; ++j)
for(int k = 0; k < 2; ++k)
for (int l= 0; l < 3; ++l) {
{
Bit b1(b[i], p[j]);
Bit b2(b[k], p[l]);
bool res = (b1&b2).reveal(PUBLIC);
if(res != (b[i] and b[k])) {
cout<<"AND" <<i<<" "<<j<<" "<<k<<" "<<l<<" "<<res<<endl;
error("test bit error!");
}
res = (b1 & b1).reveal(PUBLIC);
if (res != b[i]) {
cout<<"AND" <<i<<" "<<j<<res<<endl;
error("test bit error!");
}
res = (b1 & (!b1)).reveal(PUBLIC);
if (res) {
cout<<"AND" <<i<<" "<<j<<res<<endl;
error("test bit error!");
}
}
{
Bit b1(b[i], p[j]);
Bit b2(b[k], p[l]);
bool res = (b1^b2).reveal(PUBLIC);
if(res != (b[i] xor b[k])) {
cout <<"XOR"<<i<<" "<<j<<" "<<k<<" "<<l<< " " <<res<<endl;
error("test bit error!");
}
res = (b1 ^ b1).reveal(PUBLIC);
if (res) {
cout<<"XOR" <<i<<" "<<j<<res<<endl;
error("test bit error!");
}
res = (b1 ^ (!b1)).reveal(PUBLIC);
if (!res) {
cout<<"XOR" <<i<<" "<<j<<res<<endl;
error("test bit error!");
}
}
}
cout <<"success!"<<endl;
}
int main(int argc, char** argv) {
setup_plain_prot(false, "");
test_bit();
finalize_plain_prot();
}