#include <iostream>
#include <cstdint>
#include <vector>
#include <bitset>
// XOR two byte arrays of the same length
std::vector<uint8_t> xorBytes(const std::vector<uint8_t>& a, const std::vector<uint8_t>& b) {
std::vector<uint8_t> result(a.size());
for (size_t i = 0; i < a.size(); ++i) {
result[i] = a[i] ^ b[i];
}
return result;
}
// Print byte array as bitset
void printBitsetArray(const std::string& label, const std::vector<uint8_t>& array) {
std::cout << label << ": ";
for (auto ch : array)
std::cout << std::bitset<8>(ch) << ' ';
std::cout << '\n';
}
int main() {
std::vector<uint8_t> a{'A', 'e', 'r', 'y', 'n'};
std::vector<uint8_t> b{'A', 'l', 'b', 'u', 's'};
std::vector<uint8_t> c = xorBytes(a, b);
printBitsetArray("a", a);
printBitsetArray("b", b);
printBitsetArray("c", c);
std::cout << "c: ";
for (auto ch : c)
std::cout << static_cast<int>(ch) << ' ';
}
/*
run:
a: 01000001 01100101 01110010 01111001 01101110
b: 01000001 01101100 01100010 01110101 01110011
c: 00000000 00001001 00010000 00001100 00011101
c: 0 9 16 12 29
*/