// File: /workspace/github_cpp_makefile_star2_O2/rupc[P]xor-secret-sharing-scheme/main.cpp
// Function: main
int main(int argc, char *argv[])
{
    srand (time(NULL));
    XORSecretShares xss(128);
    std::cout << "original secret" << "\n";
    std::string orig_secret = xss.generate_random_secret();
    std::cout << orig_secret << "\n\n";
    std::cout << "shadows" << "\n";
    auto shadows = xss.split(14);

    for (const auto &p : shadows) {
        std::cout << p << "\n";
    }

    std::cout << "\n";
    std::cout << "All shadows are XOR-ed" << "\n";

    auto key_size = xss.get_key_size();
    std::string xored_share = shadows[0];

    for (int i = 1; i < shadows.size(); i++) {
        switch (key_size) {
            case 64: {
                std::bitset<64> xored_share_64(xored_share);
                std::bitset<64> share_64(shadows[i]);
                xored_share = (xored_share_64^=share_64).to_string();
            }
                break;
            case 128: {
                std::bitset<128> xored_share_128(xored_share);
                std::bitset<128> share_128(shadows[i]);
                xored_share = (xored_share_128^=share_128).to_string();
            }
                break;
            case 256: {
                std::bitset<256> xored_share_256(xored_share);
                std::bitset<256> _share_256(shadows[i]);
                xored_share = (xored_share_256^=_share_256).to_string();
            }
                break;
            default: {
                std::bitset<64> xored_share_64(xored_share);
                std::bitset<64> _share_64(shadows[i]);
                xored_share = (xored_share_64^=_share_64).to_string();
            }
                break;
        }
        
    }

    std::cout << "Retrived Secret" << "\n";
    std::cout << xored_share << "\n";

    std::cout << "Original Secret" << "\n";
    std::cout << orig_secret << "\n";

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
xorl %edi, %edi
callq 0x2100
movl %eax, %edi
callq 0x2120
leaq -0x118(%rbp), %r13
movl $0x80, -0x8(%r13)
leaq -0x108(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
andq $0x0, 0x40(%rax)
movb $0x1, -0x14(%rax)
movq 0x37a4(%rip), %rdi      # 0x5fd0
leaq 0x17d7(%rip), %rsi      # 0x400a
callq 0x2130
leaq 0x17dc(%rip), %rsi      # 0x401b
movq %rax, %rdi
callq 0x2130
leaq -0xc0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x22fc
movq 0x376f(%rip), %rdi      # 0x5fd0
leaq -0xc0(%rbp), %rsi
callq 0x20f0
leaq 0x17a6(%rip), %rsi      # 0x401a
movq %rax, %rdi
callq 0x2130
movq 0x374d(%rip), %rdi      # 0x5fd0
leaq 0x1793(%rip), %rsi      # 0x401d
callq 0x2130
leaq 0x1785(%rip), %rsi      # 0x401b
movq %rax, %rdi
callq 0x2130
leaq -0x40(%rbp), %rdi
leaq -0x120(%rbp), %rsi
pushq $0xe
popq %rdx
callq 0x24bc
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %rbx
movq 0x3710(%rip), %r15      # 0x5fd0
leaq 0x1754(%rip), %r12      # 0x401b
cmpq %rbx, %r14
je 0x28e8
movq %r15, %rdi
movq %r14, %rsi
callq 0x20f0
movq %rax, %rdi
movq %r12, %rsi
callq 0x2130
addq $0x20, %r14
jmp 0x28c7
movq 0x36e1(%rip), %rdi      # 0x5fd0
leaq 0x1725(%rip), %rsi      # 0x401b
callq 0x2130
movq 0x36ce(%rip), %rdi      # 0x5fd0
leaq 0x171c(%rip), %rsi      # 0x4025
callq 0x2130
leaq 0x1706(%rip), %rsi      # 0x401b
movq %rax, %rdi
callq 0x2130
movl -0x120(%rbp), %ebx
movq -0x40(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x2170
pushq $0x1
popq %r13
pushq $0x20
popq %r15
leaq -0x140(%rbp), %r14
leaq -0xa0(%rbp), %r12
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
sarq $0x5, %rax
cmpq %r13, %rax
jbe 0x2aa4
cmpl $0x100, %ebx            # imm = 0x100
je 0x29f8
cmpl $0x80, %ebx
je 0x29b3
cmpl $0x40, %ebx
jne 0x2a4e
movq %r12, %rdi
leaq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x2c32
movq -0x40(%rbp), %rsi
addq %r15, %rsi
leaq -0x80(%rbp), %rdi
xorl %edx, %edx
callq 0x2c32
movq -0x80(%rbp), %rax
xorq %rax, -0xa0(%rbp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2f16
jmp 0x2a84
movq %r12, %rdi
leaq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x2c72
movq -0x40(%rbp), %rsi
addq %r15, %rsi
leaq -0x80(%rbp), %r12
movq %r12, %rdi
xorl %edx, %edx
callq 0x2c72
leaq -0xa0(%rbp), %rdi
movq %r12, %rsi
movq %rdi, %r12
callq 0x34b4
movq %r14, %rdi
movq %r12, %rsi
callq 0x306a
jmp 0x2a84
movq %r14, %rdi
leaq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x2cb4
movq -0x40(%rbp), %rsi
addq %r15, %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x2cb4
movq %r14, %rdi
movq %r12, %rsi
callq 0x34d0
leaq -0x80(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x31cc
leaq -0x60(%rbp), %rdi
movq %r12, %rsi
callq 0x2160
movq %r12, %rdi
callq 0x2080
leaq -0xa0(%rbp), %r12
jmp 0x2a98
movq %r12, %rdi
leaq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x2c32
movq -0x40(%rbp), %rsi
addq %r15, %rsi
leaq -0x80(%rbp), %rdi
xorl %edx, %edx
callq 0x2c32
movq -0x80(%rbp), %rax
xorq %rax, -0xa0(%rbp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2f16
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
callq 0x2160
movq %r14, %rdi
callq 0x2080
incq %r13
addq $0x20, %r15
jmp 0x2946
movq 0x3525(%rip), %rdi      # 0x5fd0
leaq 0x158a(%rip), %rsi      # 0x403c
callq 0x2130
leaq 0x155d(%rip), %rsi      # 0x401b
movq %rax, %rdi
callq 0x2130
movq 0x3503(%rip), %rdi      # 0x5fd0
leaq -0x60(%rbp), %rsi
callq 0x20f0
leaq 0x153e(%rip), %rsi      # 0x401b
movq %rax, %rdi
callq 0x2130
movq 0x34e4(%rip), %rdi      # 0x5fd0
leaq 0x1559(%rip), %rsi      # 0x404c
callq 0x2130
leaq 0x151c(%rip), %rsi      # 0x401b
movq %rax, %rdi
callq 0x2130
movq 0x34c2(%rip), %rdi      # 0x5fd0
leaq -0xc0(%rbp), %rsi
callq 0x20f0
leaq 0x14fa(%rip), %rsi      # 0x401b
movq %rax, %rdi
callq 0x2130
leaq -0x60(%rbp), %rdi
callq 0x2080
leaq -0x40(%rbp), %rdi
callq 0x2d8c
leaq -0xc0(%rbp), %rdi
callq 0x2080
leaq -0x118(%rbp), %rdi
callq 0x2080
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x2ba0
jmp 0x2b77
jmp 0x2b70
movq %rax, %r14
jmp 0x2bc1
jmp 0x2ba9
movq %rax, %r14
jmp 0x2bb5
jmp 0x2b94
jmp 0x2b94
jmp 0x2b94
jmp 0x2b94
jmp 0x2b94
jmp 0x2b94
jmp 0x2b94
jmp 0x2b94
jmp 0x2b94
jmp 0x2b94
jmp 0x2b94
jmp 0x2b94
movq %rax, %r14
leaq -0x60(%rbp), %rdi
callq 0x2080
leaq -0x118(%rbp), %r13
jmp 0x2bac
movq %rax, %r14
leaq -0x40(%rbp), %rdi
callq 0x2d8c
leaq -0xc0(%rbp), %rdi
callq 0x2080
movq %r13, %rdi
callq 0x2080
movq %r14, %rdi
callq 0x21b0